Skip to content

[Kotlin-spring] fix model inheritance#10365

Open
frecco75 wants to merge 3 commits intoOpenAPITools:masterfrom
galeries-lafayette:fix/kotlin-inheritance
Open

[Kotlin-spring] fix model inheritance#10365
frecco75 wants to merge 3 commits intoOpenAPITools:masterfrom
galeries-lafayette:fix/kotlin-inheritance

Conversation

@frecco75
Copy link
Copy Markdown

@frecco75 frecco75 commented Sep 10, 2021

This PR fixes kotlin classes generation with inherited models in the source schema.

For example given this schema

openapi: "3.0.1"
info:
  version: 1.0.0
  title: Users

paths:
  /users:
    get:
      responses:
        200:
          description: users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
  
  
components:
  schemas:
    User:
      type: object
      required:
        - name
      properties:
        name:
          type: string
      discriminator:
        propertyName: type

    Admin:
      title: Admin
      allOf:
        - $ref: '#/components/schemas/User'
        - type: object
          required:
            - role
          properties:
            role:
              type: string

With the fix the generated code is valid and compiles correctly.

Moreover, it's better to use JsonTypeInfo.As.EXISTING_PROPERTY to avoid duplicate name in the JSON response

@frecco75 frecco75 force-pushed the fix/kotlin-inheritance branch from 9d3d2d5 to 973315f Compare September 10, 2021 12:44
@frecco75 frecco75 changed the title fix kotlin inheritance [Kotlin-spring] fix model inheritance Sep 10, 2021
@wing328
Copy link
Copy Markdown
Member

wing328 commented Sep 14, 2021

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@wing328
Copy link
Copy Markdown
Member

wing328 commented Sep 14, 2021

cc @jimschubert (2017/09) ❤️, @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03)

@frecco75 frecco75 force-pushed the fix/kotlin-inheritance branch from e4501b4 to edf9c7c Compare September 14, 2021 07:40
@frecco75
Copy link
Copy Markdown
Author

Thanks @wing328. I have edited the commit!

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Sep 14, 2021

@frecco75 Did you run the following commands to build the project and update samples?

./mvnw clean package 
./bin/generate-samples.sh
./bin/utils/export_docs_generators.sh

@frecco75
Copy link
Copy Markdown
Author

frecco75 commented Sep 14, 2021

@4brunu Yes I did it.

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Sep 14, 2021

Thanks, I asked because I was expecting to see some changes in the sample projects

@wing328
Copy link
Copy Markdown
Member

wing328 commented Sep 16, 2021

Please resolve the merge conflicts when you've time.

@frecco75 frecco75 force-pushed the fix/kotlin-inheritance branch from 4439337 to 2325cad Compare September 20, 2021 08:25
@frecco75 frecco75 force-pushed the fix/kotlin-inheritance branch from 2325cad to d2a96b9 Compare September 20, 2021 08:26
@frecco75
Copy link
Copy Markdown
Author

@wing328 done

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants