-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle references to schemas with illegal names
- Loading branch information
Showing
41 changed files
with
256 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hey-api/openapi-ts': patch | ||
--- | ||
|
||
fix: handle references to schemas with illegal names |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const refParametersPartial = '#/components/parameters/'; | ||
|
||
export const refSchemasPartial = '#/components/schemas/'; |
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,37 @@ | ||
import { getType } from '../openApi/common/parser/type'; | ||
import { refParametersPartial, refSchemasPartial } from './const'; | ||
import { reservedWordsRegExp } from './reservedWords'; | ||
|
||
export const getParametersMeta = (definitionName: string) => { | ||
const definitionType = getType({ type: definitionName }); | ||
/** | ||
* Prefix parameter names to avoid name conflicts with schemas. | ||
* Assuming people are mostly interested in importing schema types | ||
* and don't care about this name as much. It should be resolved in | ||
* a cleaner way, there just isn't a good deduplication strategy | ||
* today. This is a workaround in the meantime, hopefully reducing | ||
* the chance of conflicts. | ||
* | ||
* Example where this would break: schema named `ParameterFoo` and | ||
* parameter named `Foo` (this would transform to `ParameterFoo`) | ||
* | ||
* Note: there's a related code to this workaround in `getType()` | ||
* method that needs to be cleaned up when this is addressed. | ||
*/ | ||
const name = `Parameter${definitionType.base.replace(reservedWordsRegExp, '_$1')}`; | ||
const meta = { | ||
$ref: refParametersPartial + definitionName, | ||
name, | ||
}; | ||
return meta; | ||
}; | ||
|
||
export const getSchemasMeta = (definitionName: string) => { | ||
const definitionType = getType({ type: definitionName }); | ||
const name = definitionType.base.replace(reservedWordsRegExp, '_$1'); | ||
const meta = { | ||
$ref: refSchemasPartial + definitionName, | ||
name, | ||
}; | ||
return meta; | ||
}; |
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
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.