misl / openapi-validator-maven-plugin

Plugin to validate and merge splitted OpenAPI specification files.
6 stars 1 forks source link

Date examples not correct in the final validated and consolidated output swagger file. #43

Closed abhijeetgiri20 closed 2 years ago

abhijeetgiri20 commented 2 years ago

Background:

We have multiple APIs in our application and so we have kept some common components, schemas & parameters in common external files which are referenced in the API specs. So, we use this validator plugin to validate and consolidate the API specs into a single file via resolving all external refs. Pretty standard use.

Bug:

As seen below, we have this schema declaration for a date field in our API specs along with an example. Now if we see the API spec as it is in the swagger editor we see this date field example correctly i.e startDate: "2021-11-11". But if see the generated swagger file from this plugin in the swagger editor, this date field example is NOT correct. It gets displayed as - startDate: {}.

Checking the schema section in swagger editor it says: startDate: string($date), example: OrderedMap {}.

Issue is that after validation when the final swagger file is generated, the date field example's quotes are getting removed.

Its a problem because the standard way of conveying the date format related information to the API client is not functional. We have to rely on other indirect ways to do this.

Our plugin configuration: using version 1.0.2

<configuration>
    <inputSpec>
        ${project.basedir}/src/main/resources/META-INF/resources/api/api.yaml
    </inputSpec>
    <outputPath>${project.build.directory}/output/api</outputPath>
    <outputFilename>AppAPI</outputFilename>
    <outputFormat>YAML</outputFormat>
    <prettyPrint>true</prettyPrint>
</configuration>

API spec

openapi: 3.0.3
components:
  schemas:
    startDate:
      type: string
      format: date
      example: "2021-11-11"

Generated final output file

openapi: 3.0.3
components:
  schemas:
    startDate:
      type: string
      format: date
      example: 2021-11-11  # no quotes here
misl commented 2 years ago

In YAML double quotes are not needed for strings. In addition, it is the underlying swagger parser that does the heavy lifting (maven plugin is just a thin wrapper). If it would be an error it is an error of the swagger parser.