Skip to content
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

New option to map inline schema names #12237

Merged
merged 10 commits into from
Apr 26, 2022
Merged

New option to map inline schema names #12237

merged 10 commits into from
Apr 26, 2022

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Apr 25, 2022

New option to map inline schema names, e.g.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i  modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml -o /tmp/java3/ --skip-validate-spec --inline-schema-name-mappings inline_object_2=SomethingMapped,inline_object_4=nothing_new

Here are what the log looks like:

[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as inline_object_1. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as inline_response_200. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as inline_response_200_1. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as inline_object_3. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as inline_response_200_2. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @OpenAPITools/generator-core-team

@wing328 wing328 marked this pull request as ready for review April 26, 2022 04:18
@wing328 wing328 added this to the 6.0.0 milestone Apr 26, 2022
@wing328 wing328 merged commit 53eebc9 into master Apr 26, 2022
@wing328 wing328 deleted the better-inline-naming branch May 2, 2022 13:47
@wing328 wing328 added the Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf label May 13, 2022
@c0dezli
Copy link

c0dezli commented Jul 11, 2022

Is there any way to disable this behavior? This is causing some regression bugs on our end. What if we don't want to have inline models created at all?

@c0dezli
Copy link

c0dezli commented Jul 11, 2022

This PR causes a critical regression bug

Let's say we have an object defined in my OpenAPI 3.0.3 schema

    LoginPasswordlessResponse:
      type: object
      properties:
        user:
          allOf:
          - $ref: '#/components/schemas/BaseUser'
          nullable: true
        token:
          type: string
          nullable: true

Before this PR, the OpenAPI generator will link LoginPasswordlessResponse.user to BaseUser without creating a redundant inline model.

But now it will create a new model called LoginPasswordlessResponse_user

[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as LoginPasswordlessResponse_user. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option (--inline-schema-name-mapping in CLI).

And I cannot overwrite it with --inline-schema-name-mappings option because if I overwrite LoginPasswordlessResponse_user with BaseUser the whole openapi generator will just break.

(and by the way you missed the ending "s" in the log output, which is very misleading. I spend hours on figuring out why --inline-schema-name-mapping is an invalid option, turns out it should be --inline-schema-name-mappings)

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

Successfully merging this pull request may close these issues.

2 participants