Skip to content

OneOf not generating all options #145

Description

@thiagonuic

Hi, thanks for providing such a library for the community. We are using redoc in our code and we found a potential issue in the generated JSON and we traced it down to this library. I compared the OpenAPI doc we generate using the https://editor.swagger.io/ to see if we were diverging from what is expected and apparently it is a bug here in openapi-sampler.

It happens when we use the OneOf and it generates the wrong output. To best exemplify, I created a test for the object.spec.js file.

Please let me know what you think.

  it('should generate both items of oneOf', () => {
    res = sampleObject({
      'type': 'object',
      'properties': {
        'my_obj': {
          'type': 'object',
          'properties': {
            'elements': {
              'items': {
                'oneOf': [
                  {
                    'type': 'object',
                    'properties': {
                      'name': {
                        'type': 'string',
                        'description': '',
                        'enum': [
                          'obj_a'
                        ]
                      }
                    },
                    'title': 'obj_a',
                    'required': [
                      'name'
                    ]
                  },
                  {
                    'type': 'object',
                    'properties': {
                      'name': {
                        'type': 'string',
                        'description': '',
                        'enum': [
                          'obj_b'
                        ]
                      }
                    },
                    'title': 'obj_b',
                    'required': [
                      'name'
                    ]
                  }
                ]
              },
              'type': 'array',
              'minItems': 2,
              'maxItems': 2,
              'uniqueItems': true
            }
          },
          'title': '',
          'required': [
            'elements'
          ]
        }
      },
      'required': [
        'my_obj'
      ]
    })

    expect(res).deep.equal({
      'my_obj': {
        'elements': [
          {
            'name': 'obj_a'
          },
          {
            'name': 'obj_b'
          }
        ]
      }
    })
  });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions