devdigital / gatsby-source-openapi-aggregate

Gatsby source plugin for pulling data into Gatsby from Open API/Swagger specifications
MIT License
27 stars 13 forks source link

childOpenApiSpecResponse.childrenOpenApiSpecDefinition doesn't contain all referenced definitions #5

Open sb8244 opened 6 years ago

sb8244 commented 6 years ago

The current childrenOpenApiSpecDefinition contains the primary definition only. The definition may reference other definitions (recursively?) to build up the full tree of definitions. I have this working locally for my 1-level nesting using the code:

        const definitionId = ref ? ref.replace('#/definitions/', '') : null;

        let children = definitionId ? [`${rootId}.definition.${definitionId}`] : [];

        if (definitionId) {
          const mainDefinition = definitions.filter(definition => definition.fields.name === definitionId)[0];
          const referencedDefinitions =
            mainDefinition.fields.properties.
              map(prop => prop.referencedDefinition).
              filter((p) => p).
              map(id => `${rootId}.definition.${id}`);

          children = children.concat(Array.from(new Set(referencedDefinitions)));
        }

        return {
          id: `${rootId}.path.${p}.verb.${v}.response.${r}`,
          parent: `${rootId}.path.${p}.verb.${v}`,
          children,
          fields: {
            statusCode: r,
            description: response.description
          }
        };
devdigital commented 6 years ago

Thank you for the report, work has started on another branch which is looking to deal with recursive definitions, I'm hoping to pick this up again early next week.