OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.86k stars 6.59k forks source link

[BUG] [python-experimental] fails to deserialize openapi json file #13225

Closed fbl100 closed 2 years ago

fbl100 commented 2 years ago

Bug Report Checklist

Description

python-experimental is failing to convert a json file to a model

Failure is here: python-experimental\python-client\openapi_client\schemas.py", line 1605, in __get_oneof_class raise ApiValueError( openapi_client.exceptions.ApiValueError: Invalid inputs given to generate an instance of <class 'openapi_client.model.orbit_state_spec.OrbitStateSpec'>. Multiple oneOf schemas [<class 'openapi_client.model.cartesian_orbit_state_spec.CartesianOrbitStateSpec'>, <class 'openapi_client.model.tle_orbit_spec.TLEOrbit Spec'>] matched the inputs, but a max of one is allowed.

openapi-generator version

latest (8/18/2022 snapshot build)

OpenAPI declaration file content or url

OpenAPI Spec: https://gist.github.com/fbl100/05a3b86fa93a8dec5912c679ce349500

{
    "asset_id": "ISS",
    "state_vector_provider": {
        "initial_state": {
            "type_id": "TLE",
            "tle_line_1": "1 25544U 98067A   22230.54298192  .00005377  00000+0  10137-3 0  9995",
            "tle_line_2": "2 25544  51.6425  27.6781 0005496 134.4097 303.3608 15.50216541354856"
        },
        "interpolation_step_sec": 90.0,
        "type_id": "SGP4"
    }
}

python test:

import json

from openapi_client.model.asset_spec import AssetSpec

with open("asset.json") as f:
    data = json.load(f)
    print(data)
    a = AssetSpec._from_openapi_data(data)
    print(a)
Generation Details

generated client using docker image:

docker run --rm -v "${PWD}:/output" `
                -v "${PWD}:/input" `
                openapitools/openapi-generator-cli:latest generate `
                -g python-experimental `
                -i /input/asset_store.v1.yml `
                -o /output/python-client
Steps to reproduce

generated client as above ran pip install ./python-client ran python test.py

Related issues/PRs
Suggest a fix
spacether commented 2 years ago

This error applies to initial_state values.

{
    "type_id": "TLE",
    "tle_line_1": "1 25544U 98067A   22230.54298192  .00005377  00000+0  10137-3 0  9995",
    "tle_line_2": "2 25544  51.6425  27.6781 0005496 134.4097 303.3608 15.50216541354856"
}

CartesianOrbitStateSpec schema:

    CartesianOrbitStateSpec:
      title: CartesianOrbitStateSpec
      description: |
        CartesianOrbitStateSpec defines a set of state vectors that can
        be used to initialize a propagator
      allOf:
        - $ref: '#/components/schemas/BaseOrbitStateSpec'
        - type: object
          properties:
            type_id:
              type: string
              default: CARTESIAN
              description: CARTESIAN
            pos_km:
              type: array
              description: The position vector in the specified reference frame (km)
              minItems: 3
              maxItems: 3
              items:
                type: number
                format: double
            vel_km:
              type: array
              description: The velocity vector in the specified reference frame (km/sec)
              minItems: 3
              maxItems: 3
              items:
                type: number
                format: double
          required:
            - type_id
    BaseOrbitStateSpec:
      title: BaseOrbitStateSpec
      type: object
      description: |
        Defines common parameters for Cartesian and Keplerian orbits
      properties:
        epoch:
          type: string
          format: date-time
          description: 'ISO 8601 Formatted Date (Zulu time zone only).  If not specified, the simulation start time will be used'
        reference_frame:
          $ref: '#/components/schemas/ReferenceFrame'
    ReferenceFrame:
      type: string
      title: ReferenceFrame
      description: 'The reference frame of the attitude or orbital element.  Assets should use J2000, Payloads should use SC_BODY (Spacecraft Body) NORAD TLE''s are typically specified in TEME (True Equator Mean Equinox)'
      enum:
        - J2000
        - MOD
        - TOD
        - TEME
        - ECEF
        - SC_BODY
      example: ECEF
spacether commented 2 years ago

Schema for TLEOrbitSpec

    TLEOrbitSpec:
      title: TLEOrbitSpec
      type: object
      properties:
        type_id:
          type: string
          default: TLE
          description: TLE
        tle_line_1:
          type: string
          description: 'When specified, all orbit fields except Propagator must be blank'
        tle_line_2:
          type: string
          description: 'When specified, all orbit fields except Propagator must be blank'
      required:
        - type_id
        - tle_line_1
        - tle_line_2
      description: |
        For use when defining an orbit using NORAD TLE's
spacether commented 2 years ago

This is a spec issue, not a generator issue

The payload matches both schemas because in CartesianOrbitStateSpec all properties are optional except type_id and any properties are allowed in because additionalProperties is unset. This is the expected behavior. You can learn more about additionalProperties here.

To fix this you can:

spacether commented 2 years ago

Closing because this is a spec issue, not a generator issue