Skip to content

[Core] oneOf schema properties #4515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
lwlee2608 opened this issue Nov 17, 2019 · 6 comments
Closed
5 tasks done

[Core] oneOf schema properties #4515

lwlee2608 opened this issue Nov 17, 2019 · 6 comments

Comments

@lwlee2608
Copy link
Contributor

lwlee2608 commented Nov 17, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

vars missing from model if they are given oneOf rule

openapi-generator version

4.2.2-SNAPSHOT

OpenAPI declaration file content or url
    Area:
      type: object
      oneOf:
        - required:
          - tacs
        - required:
          - areaCode
      properties:
        tacs:
          type: array
          items:
            $ref: '#/components/schemas/Tac'
          minItems: 1
        areaCode:
            $ref: '#/components/schemas/AreaCode'
Steps to reproduce

checkout from here
./run.sh

The generated code won't compile because Area is missing properties tacs and areaCode

Suggest a fix

call addVars from schema.properties here
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L1939

lwlee2608 added a commit to lwlee2608/openapi-generator that referenced this issue Nov 17, 2019
@spacether
Copy link
Contributor

spacether commented Nov 17, 2019

This other pr also attempts to fix this issue
#4482

@lwlee2608
Copy link
Contributor Author

@spacether I see, the fix is also identical. And it comes with tests, nice.

@jimschubert
Copy link
Member

@lwlee2608 can you run your spec through an online validator? oneOf should be an array of Schemas, but what you've presented as an example shouldn't be valid. Additionally, oneOf technically shouldn't have any additional properties besides discriminator, although I've seen this numerous times.

For example, using this spec:

openapi: "3.0.1"
info:
   title: title
   version: 0.0.1
paths:
   /:
      get:
         responses:
            '200':
               description: none
               content:
                  application/json:
                     schema:
                        $ref: '#/components/schemas/Area'
components:
   schemas:
      AreaCode:
         title: AreaCode
         type: object
         properties:
            value:
               type: string
      Tac:
         type: object
         properties:
            count:
               type: number
            type:
               type: string
      Area:
         type: object
         oneOf:
         - required:
            - tacs
         - required:
            - areaCode
         properties:
         tacs:
            type: array
            items:
               $ref: '#/components/schemas/Tac'
            minItems: 1
         areaCode:
               $ref: '#/components/schemas/AreaCode'

You should see multiple errors in OpenAPI Generator's validation:

openapi-generator validate -i ~/Documents/sam.yml --recommend
Validating spec (/Users/jim/Documents/sam.yml)
Errors:
	-attribute components.schemas.Area.properties is not of type `object`
	-attribute components.schemas.Area.areaCode is unexpected
	-attribute components.schemas.Area.tacs is unexpected
Warnings:
	-Unused model: Tac
	-Unused model: AreaCode

[error] Spec has 3 errors.

You've ticked the validation TODO item in the description, but my above minimal spec fails validation in the linked validator:

image

@lwlee2608
Copy link
Contributor Author

lwlee2608 commented Dec 8, 2019

@jimschubert
I have run the validator before it is valid. The schema file I was using can be found here

The difference is AreaCode and Tac is defined as primitive string in my case

@lwlee2608
Copy link
Contributor Author

full-blown original 3gpp schema file can be found here

@spacether
Copy link
Contributor

Should be fixed by #4482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants