Skip to content
New issue

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

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

Already on GitHub? # to your account

OpenAPI v2 converter - minLength, maxLength and pattern not migrated #708

Closed
jmini opened this issue May 16, 2018 · 1 comment
Closed

OpenAPI v2 converter - minLength, maxLength and pattern not migrated #708

jmini opened this issue May 16, 2018 · 1 comment

Comments

@jmini
Copy link
Contributor

jmini commented May 16, 2018

Consider this OAS3 spec (testMinMax3.yaml):

openapi: 3.0.1
info:
  title: OpenAPI Test
  description: Test
  license:
    name: Apache-2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
- url: http://localhost:9999/v2
paths:
  /ping:
    post:
      summary: test
      description: test it
      operationId: pingOp
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SomeObj'
        required: true
      responses:
        200:
          description: OK
          content: {}
components:
  schemas:
    SomeObj:
      type: string
      minLength: 1
      maxLength: 3

Now I can run this test:

@Test
public void testOas3() {
    final OpenAPI openAPI = new OpenAPIParser().readLocation(“../testMinMax3.yaml", null, new ParseOptions()).getOpenAPI();

    Schema s = openAPI.getComponents().getSchemas().get("SomeObj");
    Assert.assertEquals(s.getMinLength(), Integer.valueOf(1));
    Assert.assertEquals(s.getMaxLength(), Integer.valueOf(3));
}

This is fine.


Now when you do the same with OAS2, the min and max are not correctly migrated:

With this spec (testMinMax2.yaml) :

swagger: '2.0'
info:
  description: 'Test'
  version: 1.0.0
  title: OpenAPI Test
  license:
    name: Apache-2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io
basePath: /v2
schemes:
  - http
paths:
  /ping:
    post:
      summary: test
      description: 'test it'
      operationId: pingOp
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          required: true
          schema:
            $ref: '#/definitions/SomeObj'
      responses:
        '200':
          description: OK
definitions:
  SomeObj:
    type: string
    minLength: 1
    maxLength: 3

This test is failing:

    @Test
    public void testOas2() {
        final OpenAPI openAPI = new OpenAPIParser().readLocation(“../testMinMax2.yaml", null, new ParseOptions()).getOpenAPI();
        
        Schema s = openAPI.getComponents().getSchemas().get("SomeObj");
        Assert.assertEquals(s.getMinLength(), Integer.valueOf(1)); //java.lang.AssertionError: expected [1] but found [null]
        Assert.assertEquals(s.getMaxLength(), Integer.valueOf(3)); //java.lang.AssertionError: expected [3] but found [null]
    }
@jmini jmini changed the title OpenAPI v2 converter - minLength and maxLength not migrated OpenAPI v2 converter - minLength, maxLength and pattern not migrated May 17, 2018
@frantuma
Copy link
Member

implemented in #714

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants