swagger-api / swagger-api/swagger-parser

Unable parse definition file in windows with read function

Open
#1,517 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

I am trying to parse an OpenAPI definition on a windows machine. The parsed OpenAPI is missing the requestBody which refers to a custom schema called User in this case. I have included the yaml file and also the parse output from debugging.

Following is the java code. I am using implementation "io.swagger.parser.v3:swagger-parser:2.0.24" dependency to parse.

String definitionPath = "G:\\openapi\\src\\test\\resources\\requestBody.yaml"
OpenAPI api = new OpenAPIV3Parser().read(definitionPath);

I found that parsing fails midway at:
https://github.com/swagger-api/swagger-parser/blob/8b9d8e0501d0867fa5db81f81fb6bf916e759dc4/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java#L421

Following is the content of the requestBody.yaml file:

openapi: 3.0.0
info:
  title: refComponent
  description: refComponent
  version: 1.0.0
servers:
  - url: 'https'
paths:
  /requestBody:
    post:
      summary: Creates a new user.
      responses:
        200:
          description: OK
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      type: object
      required:
        - userName
      properties:
        userName:
          type: string
        firstName:
          type: string
        lastName:
          type: string

The output of the parsing:

class OpenAPI {
    openapi: 3.0.1
    info: class Info {
        title: refComponent
        description: refComponent
        termsOfService: null
        contact: null
        license: null
        version: 1.0.0
    }
    externalDocs: null
    servers: [class Server {
        url: /
        description: null
        variables: null
    }]
    security: null
    tags: null
    paths: class Paths {
        {/requestBody=class PathItem {
            summary: null
            description: null
            get: null
            put: null
            post: class Operation {
                tags: null
                summary: Creates a new user.
                description: null
                externalDocs: null
                operationId: null
                parameters: null
                requestBody: null
                responses: class ApiResponses {
                    {200=class ApiResponse {
                        description: OK
                        headers: null
                        content: class Content {
                            {}
                        }
                        links: null
                        extensions: {}
                        $ref: null
                    }}
                    extensions: null
                }
                callbacks: null
                deprecated: null
                security: null
                servers: null
            }
            delete: null
            options: null
            head: null
            patch: null
            trace: null
            servers: null
            parameters: null
            $ref: null
        }}
    }
    components: class Components {
        schemas: null
        responses: null
        parameters: null
        examples: null
        requestBodies: null
        headers: null
        securitySchemes: null
        links: null
        callbacks: null
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with OpenAPIDeserializer.java around the reported line 421 and reproduce the issue using OpenAPIV3Parser().read with the supplied Windows path and requestBody.yaml. Done means the parsed OpenAPI retains the requestBody and the User schema reference instead of returning null values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.