elasticio / odata2openapi

OData to OpenAPI Converter
https://www.elastic.io
MIT License
33 stars 23 forks source link

Entity Types Referenced from Another Enitty Type are not correctly converted to JSONSchema #25

Closed jhorbulyk closed 6 years ago

jhorbulyk commented 6 years ago

Consider the metadata/TripPinServiceRW/$metadata) from OData's TripPin sample service/TripPinServiceRW/$metadata). It contains the Location entity type which is as follows

<ComplexType Name="Location" OpenType="true">
    <Property Name="Address" Type="Edm.String" Nullable="false"/>
    <Property Name="City" Type="Microsoft.OData.SampleService.Models.TripPin.City" Nullable="false"/>
</ComplexType>

Observe that there is this definition, there is an City property which is an entity type defined elsewhere in the metadata. I would expect the JSONSchema for the Location to look like:

{
  "type": "object",
  "properties": {
    "Address": {
      "type": "string"
    },
    "City": {
      "type": "object",
      "$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.City"
    }
  }
}

Instead, we are provided

{
  "type": "object",
  "properties": {
    "Address": {
      "type": "string"
    },
    "City": {
      "type": "object"
    }
  }
}
windowcat commented 6 years ago

I would like to know when this issue can be closed? Thanks.

jhorbulyk commented 6 years ago

Fixed in https://github.com/elasticio/odata2openapi/pull/26 and published in v 1.3.0

windowcat commented 6 years ago

@jhorbulyk I still get the same issue: missing $ref with latest. Any options should I set up so that I can get $ref?

jhorbulyk commented 6 years ago

@yygott Are you able to share the metadata document that is causing you troubles? I don't observe this as the case with the TripPin metadata I linked to.

windowcat commented 6 years ago

@jhorbulyk I use the model.ts in the example odata-v4-server-mongodb as my model and below is my code to convert the model. I got same issue (see below after code) when working with swagger as using my own model.

app.use( '/api-docs/metadatatojson', (req: any, res: any) => { const options: Options = { host: req.headers.host, basePath: '/content/v1', } const doc = TestServer.$metadata().document() parse( doc ) .then( ( service ) => convert(service.entitySets, options, service.version), ) .then( ( swagger ) => res.json( swagger ), ) }) The errors are like: Resolver error at paths./Products.get.responses.200.schema.properties.value.items.properties.Details.$ref Could not resolve reference because of: Could not resolve pointer: /definitions/pa.content.Details does not exist in document

However, if I save the output of TestServer.$metadata().document() into a file and use odata-openapi tool "transform.js -dp -o=2.0" to convert, I get the expected json output. This output works with swagger UI.

Is it my source code (above) issue or some dependencies issues to cause this?

jhorbulyk commented 6 years ago

I use the model.ts in the example odata-v4-server-mongodb as my model

I can't find what you are referring to. Can you post a link?

windowcat commented 6 years ago

https://github.com/jaystack/odata-v4-server-mongodb-example

jhorbulyk commented 6 years ago

Can you create a gist with the metadata XML?