KnowledgeCaptureAndDiscovery / OBA

Ontology based APIs
Apache License 2.0
38 stars 12 forks source link

Correctly output enums in .yaml #175

Closed cweedall closed 7 months ago

cweedall commented 7 months ago

Enums are not output to .yaml currently. This PR aims to fix that.

For example, the Turtle snippet below from the Pizza Tutorial does not produce an enum for Spiciness which contains the values Hot, Medium, and Mild:

    <!-- http://www.semanticweb.org/.../pizzatutorial#Spiciness -->

    <owl:Class rdf:about="http://www.semanticweb.org/.../pizzatutorial#Spiciness">
        <owl:equivalentClass rdf:nodeID="genid51"/>
    </owl:Class>
    <owl:Class rdf:nodeID="genid51">
        <owl:oneOf rdf:parseType="Collection">
            <rdf:Description rdf:about="http://www.semanticweb.org/.../pizzatutorial#Hot"/>
            <rdf:Description rdf:about="http://www.semanticweb.org/.../pizzatutorial#Medium"/>
            <rdf:Description rdf:about="http://www.semanticweb.org/.../pizzatutorial#Mild"/>
        </owl:oneOf>
    </owl:Class>
    <owl:Axiom>
        <owl:annotatedSource rdf:resource="http://www.semanticweb.org/.../pizzatutorial#Spiciness"/>
        <owl:annotatedProperty rdf:resource="http://www.w3.org/2002/07/owl#equivalentClass"/>
        <owl:annotatedTarget rdf:nodeID="genid51"/>
    </owl:Axiom>

The expected output for this schema should be:

    Spiciness:
      description: Description not available
      enum:
      - Hot
      - Medium
      - Mild
      type: string

but without the current changes, it looks like:

    Spiciness:
      description: Description not available
      example:
        value:
          id: some_id
      properties:
        isSpicierThan:
          description: Description not available
          items:
            $ref: "#/components/schemas/Spiciness"
          nullable: true
          type: array
        description:
          description: small description
          items:
            type: string
          nullable: true
          type: array
        id:
          description: identifier
          nullable: false
          type: string
        label:
          description: short description of the resource
          items:
            type: string
          nullable: true
          type: array
        type:
          description: type of the resource
          items:
            type: string
          nullable: true
          type: array
      type: object

You can see that not only is the enum aspect of this defined class lost in the yaml output, but the individual enum values are also missing completely.

As I was making the necessary changes to support enums (based on the owl:oneOf restrictions mentioned above), I made a handful of other cleanup changes. Apologies in advance if this makes reviewing difficult.

The cleanup changes included:

I will make a future PR to try and make all of the formatting consistent throughout (but without any functional changes). These formatting updates were mostly localized to where I was already making other changes OR easy to identify/fix.

dgarijo commented 7 months ago

Thanks!