yahoo / elide

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.

Home Page:https://elide.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated OAS incorrectly sets objects as nodes

bladedancer opened this issue · comments

commented

I have an entity that contains a JSONB field - e.g. CORS configuration. This is deserialized as a strongly typed object:

@Include(rootLevel = false, name = "example")
public class Example {
...
    @Type(JsonType.class)
    private CORS cors;
...
}

Nothing special about CORS, it's just a pojo - it does not have an include annotation.

Expected Behavior

I'd expect the generated OAS to at worst refer to this as an Object and ideally generate a schema for it.

Current Behavior

It's generating the object as if it was a node in the graph.

    CORS:
      type: object
      properties:
        type:
          type: string
          description: ''
        id:
          type: string
        attributes:
          required: []
          type: object
          properties:
            accessControlAllowCredentials:
              type: boolean
              readOnly: false
              writeOnly: false
              example: null
            accessControlAllowHeaders:
              type: array
              readOnly: false
              writeOnly: false
              items:
                type: object
              example: null
            accessControlAllowMethods:
              type: array
              readOnly: false
              writeOnly: false
              items:
                type: object
              example: null
            accessControlAllowOrigin:
              type: array
              readOnly: false
              writeOnly: false
              items:
                type: object
              example: null
            accessControlExposeHeaders:
              type: array
              readOnly: false
              writeOnly: false
              items:
                type: object
              example: null
            accessControlMaxAge:
              type: integer
              format: int32
              readOnly: false
              writeOnly: false
              example: null
        relationships:
          required: []
          type: object
      description: 'Update Permissions : (PreAuthorize.Update AND has permission to lock Project Artifact)'

Possible Solution

Digging into it - the CORS is in the EntityBindings that's why getting the alias succeeds and the object is treated as a resource:

https://github.com/yahoo/elide/blob/master/elide-swagger/src/main/java/com/yahoo/elide/swagger/converter/JsonApiModelResolver.java#L78

A pojo that doesn't have an @include or @entity annotation being in the EntityDictionary seems odd but it is intended - EntityDictionary.discoverEmbeddedTypeBindings.

I presume the fix needs to be that complex attribute types are skipped by JsonApiModelResolver.