Giter VIP home page Giter VIP logo

Comments (7)

zxchris avatar zxchris commented on May 18, 2024

I've a test case for this somewhere too, thanks for the example. There has been quite a lot of work and discussion around the context of property descriptions, and I was sure we'd got this right (for example, we have lots of resources that contain addresses which are defined as a standard, reusable definition. Each address instance is different though, so the description of each address property is taken from the property and not the referenced definition.

I can confirm I can reproduce with your example. Will investigate, as we agree with you, that is the way it should be. There might be a subtle difference in our specifications. We will see...

from dapperdox.

zxchris avatar zxchris commented on May 18, 2024

If you define the second property as follows (with the $ref within an items member), then you get the result you expect (for second).

        "second": {
          "type": "object",
          "description": "second property",
          "items" : {
               "$ref": "#/definitions/MyObject"
          }
        }

items appears only mandatory for arrays (and outside of in in body). To be honest, the specification isn't that explicit, and parsers generally seem to manage. We wonder if using an items member for no array references is strictly wrong. Either way, DapperDox is not working for specifications that do not have items and that is incorrect.

Fixing....

EDIT: Actually, we're convinced "items": { "$ref": .... } is wrong for all but array types.

from dapperdox.

zxchris avatar zxchris commented on May 18, 2024

The problem seems to stem from go-openapi, the specification parser used by DapperDox. Without the "items":{} wrapper around "$ref": ... we do not get a Description returned by go-openapi.

I've opened an issue over there, so we'll see what they say. We've sent them quite a detailed report. go-openapi/spec#22

from dapperdox.

zxchris avatar zxchris commented on May 18, 2024

We've got the answer. JSON schema states that other properties in an object with $ref need to be ignored. http://json-schema.org/latest/json-schema-core.html#rfc.section.7 So what go-openapi and thus DapperDox is doing is correct.

However, wrapping $ref in an items:{} block is also (technically) wrong, as items should only be used for arrays. Because DapperDox needs to support it for arrays, it also "works" for object.

The correct solution (advised by the go-openapi guys) is this:

{
  "first": {
    "allOf" : [
      {
        "type": "object",
        "description": "first property"
      },
      {
        "$ref": "#/definitions/MyObject"
      }
    ]
  }
}

Basically, merge the partial schema object, containing type and description with the referenced object, thus adding description to MyObject (type is mandatory, so must be there).

However, the current release of DapperDox doesn't process this correctly because it expects each element of the allOf array to be a complete schema object, each with properties. We just hadn't seen or expected this use case.

We're working on a more complete solution, so will leave this issue open.

from dapperdox.

x12a1f avatar x12a1f commented on May 18, 2024

Great, thanks!

from dapperdox.

zxchris avatar zxchris commented on May 18, 2024

Still working on this. It's a little complicated!

from dapperdox.

x12a1f avatar x12a1f commented on May 18, 2024

I was testing some other schema and I found a solution with works:

{
  "first": {
    "type": "object",
    "description": "first property"
    "allOf" : [
      {
        "$ref": "#/definitions/MyObject"
      }
    ]
  }
}

I'm not sure if this is according to the spec but it is rendered as expected in dapperdox.

from dapperdox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.