Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG] Mistype in InlineModelResolver leads to autogenerated class name instead of specified by title #18574

Closed
4 of 6 tasks
vlsergey opened this issue May 5, 2024 · 1 comment · Fixed by #19173
Closed
4 of 6 tasks

Comments

@vlsergey
Copy link
Contributor

vlsergey commented May 5, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The problem occurs with following input:

components:
  schemas:
    Root:
      type: object
      additionalProperties:
        title: TestValueModel
        type: object
        properties:
          name:
            type: String

I expect number of value class to be TestValueModel. Instead it is generated as RootValue.

This is happens because of mistype in InlineModelResolver :: gatherInlineModels at line 317:

String schemaName = resolveModelName(schema.getTitle(), modelPrefix + this.inlineSchemaOptions.get("MAP_ITEM_SUFFIX"));

            // Check additionalProperties for inline models
            if (schema.getAdditionalProperties() != null) {
                if (schema.getAdditionalProperties() instanceof Schema) {
                    Schema inner = (Schema) schema.getAdditionalProperties();
                    if (inner != null) {
                        String schemaName = resolveModelName(schema.getTitle(), modelPrefix + this.inlineSchemaOptions.get("MAP_ITEM_SUFFIX"));
                        // Recurse to create $refs for inner models
                        gatherInlineModels(inner, schemaName);
                        if (isModelNeeded(inner)) {
                            // If this schema should be split into its own model, do so
                            Schema refSchema = this.makeSchemaInComponents(schemaName, inner);
                            schema.setAdditionalProperties(refSchema);
                        }
                    }
                }
            }

instead of schema.getTitle() inner schema title inner.getTitle() should be used.

openapi-generator version

6.6.0, but bug is still in trunk

Generation Details

spring generator for Java

Steps to reproduce
Related issues/PRs
Suggest a fix
@vlsergey vlsergey changed the title [BUG] Mistype in InlineModelResolver leads to autogenerated class name instead of speciifed by title [BUG] Mistype in InlineModelResolver leads to autogenerated class name instead of specified by title May 5, 2024
@wing328
Copy link
Member

wing328 commented May 6, 2024

instead of schema.getTitle() inner schema title inner.getTitle() should be used.

can you please file a PR with the suggested fix when you've time?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
2 participants