swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

Patterns in OpenAPI Fields Altered When Merging Multiple Source Files. #12163

Closed pfconrey closed 1 year ago

pfconrey commented 1 year ago
Description

When merging two OpenAPI documents into one using the maven plugin, any field that has a pattern with escape characters has the backslash ('\') duplicated in the resulting file. For example, when combining two files, one with paths and the other with components, given the following component:

  Problem:
      type: object
      description: An RFC7807 problem object.
      properties:
        type:
          type: string
          description: A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be "about:blank".
          pattern: '^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])*$'
        title:
          type: string
          description: A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization (e.g., using proactive content negotiation; see [RFC7231], Section 3.4).
          pattern: '^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])*$'
        status:
          type: integer
          description: The HTTP status code ([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
          minimum: 100
          maximum: 599
        detail:
          type: string
          description: A human-readable explanation specific to this occurrence of the problem.
          pattern: '^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])*$'
        instance:
          type: string
          description: A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
          pattern: '^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])*$'

The resulting component in the merged file looks like this, with all the backslashed in the pattern attribute duplicated:

    Problem:
      type: object
      properties:
        type:
          pattern: "^((?![\\|\\=\\;])[\\p{L}\\p{N}\\p{M}\\p{P}\\p{Zs}])*$"
          type: string
          description: "A URI reference [RFC3986] that identifies the problem type.\
            \ This specification encourages that, when dereferenced, it provide human-readable\
            \ documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]).\
            \ When this member is not present, its value is assumed to be \"about:blank\"\
            ."
        title:
          pattern: "^((?![\\|\\=\\;])[\\p{L}\\p{N}\\p{M}\\p{P}\\p{Zs}])*$"
          type: string
          description: "A short, human-readable summary of the problem type. It SHOULD\
            \ NOT change from occurrence to occurrence of the problem, except for\
            \ purposes of localization (e.g., using proactive content negotiation;\
            \ see [RFC7231], Section 3.4)."
        status:
          maximum: 599
          minimum: 100
          type: integer
          description: "The HTTP status code ([RFC7231], Section 6) generated by the\
            \ origin server for this occurrence of the problem."
        detail:
          pattern: "^((?![\\|\\=\\;])[\\p{L}\\p{N}\\p{M}\\p{P}\\p{Zs}])*$"
          type: string
          description: A human-readable explanation specific to this occurrence of
            the problem.
        instance:
          pattern: "^((?![\\|\\=\\;])[\\p{L}\\p{N}\\p{M}\\p{P}\\p{Zs}])*$"
          type: string
          description: A URI reference that identifies the specific occurrence of
            the problem. It may or may not yield further information if dereferenced.
      description: An RFC7807 problem object.
Swagger-codegen version

3.0.42

Swagger declaration file content or url

Configuration in pom.xml used for generation:

<plugin>
  <groupId>io.swagger.codegen.v3</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <version>3.0.42</version>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.build.directory}/${project.artifactId}.yaml</inputSpec>
        <language>openapi-yaml</language>
        <output>${project.build.directory}</output>
        <configOptions>
          <outputFile>${project.artifactId}.yaml</outputFile>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>
Steps to reproduce
Suggest a fix/enhancement

Don't alter anything in the source files when merging them together.

pfconrey commented 1 year ago

I see now that it's a difference of "'" vs "\"" in the resulting file.