Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: change from arrays to indexed objects
The code supports both Maps and POJOs, as I couldn’t decide on the best solution. Handlebars doesn’t properly support Maps yet, so I guess it’s POJOs for now (see handlebars-lang/handlebars.js#1679) I changed to indexed types over arrays as we can iterate over objects just as well (and in insertion order, see https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/), and with the benefit of being able to look things up by key; including in Handlebars.
- Loading branch information
Showing
17 changed files
with
374 additions
and
134 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
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
12 changes: 8 additions & 4 deletions
12
packages/core/src/__tests__/parameter-inline-models.spec.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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { createTestDocument } from './common' | ||
import * as idx from '../indexed-type' | ||
|
||
test('inline response model', async() => { | ||
const result = await createTestDocument('parameter-inline-models-v2.yml') | ||
|
||
const group1 = result.groups[0] | ||
const op1 = group1.operations[0] | ||
|
||
expect(op1.parameters!.length).toEqual(1) | ||
expect(idx.size(op1.parameters!)).toEqual(1) | ||
|
||
const param1 = op1.parameters![0] | ||
const params = idx.values(op1.parameters!) | ||
|
||
const param1 = params[0] | ||
expect(param1.name).toEqual('arg1') | ||
expect(param1.nativeType.toString()).toEqual('getTest1_arg1_enum') | ||
|
||
expect(result.models.length).toEqual(1) | ||
expect(idx.size(result.models)).toEqual(1) | ||
|
||
const model1 = result.models[0] | ||
const models = idx.values(result.models) | ||
const model1 = models[0] | ||
expect(model1.name).toEqual('getTest1_arg1_enum') | ||
}) |
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,6 @@ | ||
/* | ||
Enable switching between POJOs and Maps for our indexed object type. | ||
You must also make the switch in @openapi-generator-plus/types types.ts | ||
*/ | ||
export * from './objects' | ||
// export * from './maps' |
Oops, something went wrong.