-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add curl examples to snippets if not existing at all OpenApi P…
…arser v2 (#2092) Co-authored-by: fern-bot <[email protected]>
- Loading branch information
1 parent
5c58596
commit 85c1df5
Showing
4 changed files
with
440 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/fern-docs/cache/src/__test__/ApiDefinitionLoader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { APIV1Read } from "@fern-api/fdr-sdk"; | ||
import { | ||
ApiDefinitionId, | ||
convertToCurl, | ||
EndpointDefinition, | ||
EndpointId, | ||
ExampleEndpointCall, | ||
PropertyKey, | ||
toSnippetHttpRequest, | ||
} from "@fern-api/fdr-sdk/api-definition"; | ||
import { ApiDefinitionLoader } from "../ApiDefinitionLoader"; | ||
|
||
describe("curl snippet generation", () => { | ||
it("generates correct curl snippet", async () => { | ||
const example: ExampleEndpointCall = { | ||
path: "/test", | ||
description: "Test example", | ||
responseStatusCode: 200, | ||
name: "Test Example", | ||
pathParameters: {}, | ||
queryParameters: {}, | ||
headers: {}, | ||
requestBody: { | ||
type: "json", | ||
value: { foo: "bar" }, | ||
}, | ||
responseBody: undefined, | ||
snippets: {}, | ||
}; | ||
|
||
const endpoint: EndpointDefinition = { | ||
id: EndpointId("testEndpoint"), | ||
auth: undefined, | ||
environments: [], | ||
defaultEnvironment: undefined, | ||
pathParameters: undefined, | ||
queryParameters: undefined, | ||
requestHeaders: undefined, | ||
responseHeaders: undefined, | ||
responses: undefined, | ||
errors: undefined, | ||
examples: [example], | ||
snippetTemplates: undefined, | ||
description: undefined, | ||
availability: undefined, | ||
namespace: [], | ||
displayName: "Test Endpoint", | ||
operationId: "testEndpoint", | ||
method: "POST", | ||
path: [{ type: "literal", value: "test" }], | ||
requests: [ | ||
{ | ||
contentType: undefined, | ||
description: undefined, | ||
body: { | ||
type: "object", | ||
properties: [ | ||
{ | ||
key: PropertyKey("foo"), | ||
description: "Test object", | ||
availability: undefined, | ||
valueShape: { | ||
type: "alias", | ||
value: { | ||
type: "primitive", | ||
value: { | ||
type: "string", | ||
format: undefined, | ||
regex: undefined, | ||
minLength: undefined, | ||
maxLength: undefined, | ||
default: undefined, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
extends: [], | ||
extraProperties: undefined, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const curlCode = convertToCurl( | ||
toSnippetHttpRequest(endpoint, example, undefined), | ||
{ usesApplicationJsonInFormDataValue: false } | ||
); | ||
|
||
const loader = ApiDefinitionLoader.create( | ||
"testdomain", | ||
ApiDefinitionId("testdefinitionid") | ||
); | ||
|
||
const apiDefinition = await loader | ||
.withApiDefinition({ | ||
id: ApiDefinitionId("id"), | ||
webhooks: {}, | ||
websockets: {}, | ||
types: {}, | ||
subpackages: {}, | ||
auths: {}, | ||
globalHeaders: [], | ||
endpoints: { | ||
[EndpointId("endpoint")]: endpoint, | ||
}, | ||
}) | ||
.load(); | ||
|
||
expect(curlCode).toMatchInlineSnapshot(` | ||
"curl -X POST /test \\ | ||
-H "Content-Type: application/json" \\ | ||
-d '{ | ||
"foo": "bar" | ||
}'" | ||
`); | ||
|
||
expect( | ||
apiDefinition?.endpoints?.[EndpointId("testEndpoint")]?.examples?.[0] | ||
?.snippets?.[APIV1Read.SupportedLanguage.Curl]?.[0]?.code | ||
).toEqual(curlCode); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.