-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support bytes in the fern definition
- Loading branch information
Showing
49 changed files
with
2,851 additions
and
7 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
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
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
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
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
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
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
2 changes: 2 additions & 0 deletions
2
...ation/ir-migrations/src/migrations/v54-to-v53/__test__/fixtures/simple/definition/api.yml
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,2 @@ | ||
name: simple-api | ||
auth: bearer |
21 changes: 21 additions & 0 deletions
21
...n/ir-migrations/src/migrations/v54-to-v53/__test__/fixtures/simple/definition/service.yml
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,21 @@ | ||
types: | ||
AudioFormat: | ||
enum: | ||
- MP3 | ||
- WAV | ||
- OGG | ||
|
||
service: | ||
auth: false | ||
base-path: / | ||
endpoints: | ||
getAudioFile: | ||
method: GET | ||
path: /audio | ||
request: | ||
name: GetAudioRequest | ||
query-parameters: | ||
format: | ||
type: AudioFormat | ||
default: MP3 | ||
response: bytes |
1 change: 1 addition & 0 deletions
1
...eneration/ir-migrations/src/migrations/v54-to-v53/__test__/fixtures/simple/generators.yml
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 @@ | ||
{} |
15 changes: 15 additions & 0 deletions
15
...i/generation/ir-migrations/src/migrations/v54-to-v53/__test__/migrateFromV53ToV52.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,15 @@ | ||
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils"; | ||
import { createMigrationTester } from "../../../__test__/utils/createMigrationTester"; | ||
import { V54_TO_V53_MIGRATION } from "../migrateFromV54ToV53"; | ||
|
||
const runMigration = createMigrationTester(V54_TO_V53_MIGRATION); | ||
|
||
describe("migrateFromV54ToV53", () => { | ||
it("simple", async () => { | ||
const pathToFixture = join(AbsoluteFilePath.of(__dirname), RelativeFilePath.of("./fixtures/simple")); | ||
const migrated = await runMigration({ | ||
pathToFixture | ||
}); | ||
expect(await migrated.jsonify()).toMatchSnapshot(); | ||
}); | ||
}); |
85 changes: 85 additions & 0 deletions
85
packages/cli/generation/ir-migrations/src/migrations/v54-to-v53/migrateFromV54ToV53.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,85 @@ | ||
import { GeneratorName } from "@fern-api/configuration-loader"; | ||
import { assertNever } from "@fern-api/core-utils"; | ||
import { mapValues } from "lodash-es"; | ||
import { IrSerialization } from "../../ir-serialization"; | ||
import { IrVersions } from "../../ir-versions"; | ||
import { | ||
GeneratorWasNeverUpdatedToConsumeNewIR, | ||
GeneratorWasNotCreatedYet, | ||
IrMigration | ||
} from "../../types/IrMigration"; | ||
|
||
export const V54_TO_V53_MIGRATION: IrMigration< | ||
IrVersions.V54.ir.IntermediateRepresentation, | ||
IrVersions.V53.ir.IntermediateRepresentation | ||
> = { | ||
laterVersion: "v54", | ||
earlierVersion: "v53", | ||
firstGeneratorVersionToConsumeNewIR: { | ||
[GeneratorName.TYPESCRIPT_NODE_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.TYPESCRIPT_BROWSER_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.TYPESCRIPT]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.TYPESCRIPT_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.TYPESCRIPT_EXPRESS]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.JAVA]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.JAVA_MODEL]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.JAVA_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.JAVA_SPRING]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.PYTHON_FASTAPI]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.PYTHON_PYDANTIC]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.OPENAPI_PYTHON_CLIENT]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.OPENAPI]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.STOPLIGHT]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.POSTMAN]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.PYTHON_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.GO_FIBER]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.GO_MODEL]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.GO_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.RUBY_MODEL]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.RUBY_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.CSHARP_MODEL]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.CSHARP_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.SWIFT_MODEL]: GeneratorWasNeverUpdatedToConsumeNewIR, | ||
[GeneratorName.SWIFT_SDK]: GeneratorWasNotCreatedYet, | ||
[GeneratorName.PHP_MODEL]: GeneratorWasNotCreatedYet, | ||
[GeneratorName.PHP_SDK]: GeneratorWasNeverUpdatedToConsumeNewIR | ||
}, | ||
jsonifyEarlierVersion: (ir) => | ||
IrSerialization.V53.IntermediateRepresentation.jsonOrThrow(ir, { | ||
unrecognizedObjectKeys: "strip", | ||
skipValidation: true | ||
}), | ||
migrateBackwards: (v54): IrVersions.V53.ir.IntermediateRepresentation => { | ||
return { | ||
...v54, | ||
services: mapValues(v54.services, (service) => ({ | ||
...service, | ||
endpoints: service.endpoints.map((endpoint) => ({ | ||
...endpoint, | ||
response: convertHttpResponse(endpoint.response) | ||
})) | ||
})) | ||
}; | ||
} | ||
}; | ||
|
||
function convertHttpResponse( | ||
response: IrVersions.V54.HttpResponse | undefined | ||
): IrVersions.V53.HttpResponse | undefined { | ||
if (response == null) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
statusCode: response.statusCode, | ||
body: | ||
response.body?.type === "bytes" | ||
? IrVersions.V53.HttpResponseBody.json( | ||
IrVersions.V53.JsonResponse.response({ | ||
docs: undefined, | ||
responseBodyType: IrVersions.V53.TypeReference.unknown() | ||
}) | ||
) | ||
: (response.body as any) | ||
}; | ||
} |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
53.24.0 | ||
54.0.0 |
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
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
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 @@ | ||
53.23.0 |
Oops, something went wrong.