Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-rooms-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tim-smart/openapi-gen": minor
---

improve types for non classes.
2 changes: 1 addition & 1 deletion src/JsonSchemaGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const make = Effect.gen(function* () {
Option.map((source) => {
const isObject = "properties" in schema
if (!isObject || !isClass) {
return `export class ${name} extends ${source} {}`
return `class ${name}Schema extends ${source} {}\nexport const ${name} = ${name}Schema\nexport type ${name} = typeof ${name}Schema.Type`
}
return `export class ${name} extends ${S}.Class<${name}>("${name}")(${source}) {}`
}),
Expand Down
4 changes: 2 additions & 2 deletions src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ const operationToMethod = (operation: ParsedOperation) => {
let success = "void"
if (operation.successSchemas.size > 0) {
success = Array.from(operation.successSchemas.values())
.map((schema) => `typeof ${schema}.Type`)
.map((schema) => schema)
.join(" | ")
}
const errors = ["HttpClientError.HttpClientError", "ParseError"]
if (operation.errorSchemas.size > 0) {
errors.push(
...Array.from(operation.errorSchemas.values()).map(
(schema) => `typeof ${schema}.Type`,
(schema) => schema,
),
)
}
Expand Down