Comments (4)
Nice one, @jhodges10 👍 !
I wrote my own gatsby plugin because we rely on OpenApi Spec 3.0 features (hence transforming to OpenApi Spec 2.0 wasn't an option). Unfortunately I cannot share the code as it's closed source, but here the gist for peeps in a similar situation.
The hardest part was building the GraphQL model correctly, which is shown here:
import { parseOpenApi3 } from "./api-parser/openapi3parser"
import { ApiOperation } from "./api-parser/types/ApiOperation"
export interface Options {
specs: string[]
}
exports.sourceNodes = async ({ actions }: any, options: Options) => {
const allOperations: ApiOperation[] = []
for (let spec of options.specs) {
const operations = await parseOpenApi3(spec)
for (let operation of operations) {
allOperations.push(operation)
}
}
allOperations.forEach((operation: ApiOperation) => {
actions.createNode({
id: operation.path, // assigning a unique id through helper function
children: [], // no children at this point
parent: undefined, // no parent
internal: {
type: "ApiOperation", // A globally unique name for this node type
contentDigest: toHashCode(JSON.stringify(operation)),
},
...operation,
})
})
}
const toHashCode = (input: string): string => {
let h: number = 0
for (let i = 0; i < input.length; i++) {
h = (Math.imul(31, h) + input.charCodeAt(i)) | 0
}
return h.toString()
}
The parsing of the spec is delegating to @apidevtools/swagger-parser
.
from gatsby-source-openapi-aggregate.
Hi, thanks, that's been a plan for a while now, but currently struggling for time, so I would imagine it would be a couple of months away at least unfortunately.
from gatsby-source-openapi-aggregate.
+1 on support for OAS 3.0!
from gatsby-source-openapi-aggregate.
Figured out a solution for the meantime @bengro!
npm install -g api-spec-converter
Then in your package.json
, add this task:
"transform-docs": "api-spec-converter --from=openapi_3 --to=swagger_2 --syntax=json --order=alpha [Your OAS spec URL] > ./src/data/swagger.json"
Then also add this before your dev
/ build
phases:
"dev": "yarn transform-docs && gatsby develop",
"build": "yarn transform-docs && gatsby build",
from gatsby-source-openapi-aggregate.
Related Issues (7)
- GraphQLError: Cannot query field "allOpenApiSpec" on type "Query" HOT 3
- OpenApiSpecDefinition.properties missing example
- Incompatible with Gatsby 3 due to usage of `boundActionCreators`
- childOpenApiSpecResponse.childrenOpenApiSpecDefinition doesn't contain all referenced definitions HOT 1
- TypeError Cannot convert undefined or null to object HOT 2
- Unexpected token on develop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-source-openapi-aggregate.