swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
774 stars 526 forks source link

Getting invalid reference when used with `flatten = true` option #2109

Open TharmiganK opened 1 week ago

TharmiganK commented 1 week ago

Hi,

When I used the following OpenAPI specification file and try to get the OpenAPI object from the parser which is enabled with flatten option, the references created for inline object schemas are incorrect.

OpenAPI specification:

openapi: 3.0.1
info:
  title: SocialMedia
  version: 0.1.0
servers:
  - url: "http://{server}:{port}/socialMedia/v1"
    variables:
      server:
        default: localhost
      port:
        default: "8080"
paths:
  /admin.user:
    get:
      summary: Get admin user
      operationId: getAdminUser
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                title: admin.user schema
                type: object
                required:
                  - email
                  - id
                  - name
                properties:
                  id:
                    type: integer
                    format: int64
                  name:
                    type: string
                  email:
                    type: string

Parser code:

String openAPIFileContent = Files.readString(definitionPath);
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setFlatten(true);
SwaggerParseResult parseResult = new OpenAPIParser().readContents(openAPIFileContent, null, parseOptions);

The reference in the parsed object look like this: admin.user schema but it should be #/components/schemas/admin.user schema.