Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

'allOf' not processed correctly for property #1777

Open
devdevx opened this issue Aug 3, 2022 · 0 comments
Open

'allOf' not processed correctly for property #1777

devdevx opened this issue Aug 3, 2022 · 0 comments

Comments

@devdevx
Copy link
Contributor

devdevx commented Aug 3, 2022

Example with one schema property:

openapi: "3.0.0"
info:
  title: API-Template
  description: |
    Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/)
  version: v1

tags:
  - name: Customers
    description: "Operations and resources related to customers"

paths:
  /customers/{customerId}:
    parameters:
      - $ref: '#/components/parameters/customerIdPathParam'
    get:
      summary: Retrieve customer information
      description: Description for operation that allows retrieve customer information
      operationId: retrieveCustomerInfo
      tags:
        - Customers
      responses:
        '200':
          description: Customer response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/customer'

components:
  parameters:
    customerIdPathParam:
      name: customerId
      in: path
      required: true
      description: The id of the customer
      schema:
        $ref: '#/components/schemas/uuid'

  schemas:
    uuid:
      type: string
      format: uuid
      minLength: 36
      maxLength: 36
      pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

    customer:
      type: object
      properties:
        id:
          description: The id of the customer
          allOf:
           - $ref: '#/components/schemas/uuid'
          x-apigen-mapping:
            field: id

Code executed:

import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws IOException {
        String api;
        try (InputStream is = Main.class.getClassLoader().getResourceAsStream("template_error.yaml")) {
            api = IOUtils.toString(is, StandardCharsets.UTF_8);
        }
        OpenAPIV3Parser parser = new OpenAPIV3Parser();
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setResolveCombinators(true);
        options.setResolveFully(true);
        options.setFlatten(true);
        OpenAPI openAPI = parser.readContents(api, null, options).getOpenAPI();
        System.out.println(Yaml.mapper().writeValueAsString(openAPI));
    }
}

Output:

openapi: 3.0.0
info:
  title: API-Template
  description: |
    Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/)
  version: v1
servers:
  - url: /
tags:
  - name: Customers
    description: Operations and resources related to customers
paths:
  /customers/{customerId}:
    get:
      tags:
        - Customers
      summary: Retrieve customer information
      description: Description for operation that allows retrieve customer information
      operationId: retrieveCustomerInfo
      parameters:
        - name: customerId
          in: path
          description: The id of the customer
          required: true
          style: simple
          explode: false
          schema:
            maxLength: 36
            minLength: 36
            pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
            type: string
            format: uuid
      responses:
        "200":
          description: Customer response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/inline_response_200'
components:
  schemas:
    uuid:
      maxLength: 36
      minLength: 36
      pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
      type: string
      format: uuid
    customer:
      type: object
      properties:
        id: {}
    inline_response_200:
      type: object
      properties:
        id: {}
  parameters:
    customerIdPathParam:
      name: customerId
      in: path
      description: The id of the customer
      required: true
      style: simple
      explode: false
      schema:
        maxLength: 36
        minLength: 36
        pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
        type: string
        format: uuid

Expected result:

The id property in the customer and inline_response_200 schemas should have content and not be an empty object.

Tried with versions 2.0.33 and 2.1.1 with same result.

    <dependencies>
        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <!-- <version>2.0.33</version>-->
            <version>2.1.1</version>
        </dependency>
    </dependencies>

Seems a similar issue to #1367 but that was closed.

Thanks!

devdevx added a commit to devdevx/swagger-parser that referenced this issue Oct 10, 2022
gracekarina added a commit that referenced this issue Dec 19, 2022
Extend resolve fully and solve issues #1777 and #1802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant