Skip to content

Commit

Permalink
fix: clean up remenants of bad ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Jun 17, 2021
1 parent 07d7015 commit 9d0ef32
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"!build/**/*.test.*"
],
"devDependencies": {
"@json-schema-tools/dereferencer": "^1.5.2",
"@json-schema-tools/meta-schema": "^1.6.10",
"@types/inquirer": "^7.3.1",
"@types/jest": "^26.0.15",
Expand All @@ -47,7 +48,6 @@
"typescript": "4.2.4"
},
"dependencies": {
"@json-schema-tools/dereferencer": "^1.5.2",
"@json-schema-tools/referencer": "^1.0.4",
"@json-schema-tools/titleizer": "^1.0.5",
"@json-schema-tools/traverse": "^1.7.8",
Expand Down
12 changes: 5 additions & 7 deletions src/codegens/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ export default class Rust extends CodeGen {

protected handleUntypedObject(s: JSONSchemaObject): TypeIntermediateRepresentation {
if (s.additionalProperties) {
const refTitle = this.refToTitle(s.additionalProperties);
const typeName = this.getSafeTitle(refTitle);
const typeName = this.getSafeTitle(this.refToTitle(s.additionalProperties));
const propertyTypings = [
"#[serde(flatten)]",
`pub additional_properties: Option<${typeName}>`
Expand Down Expand Up @@ -246,7 +245,7 @@ export default class Rust extends CodeGen {
}

protected handleAnyOf(s: JSONSchemaObject): TypeIntermediateRepresentation {
return this.buildEnum(s.anyOf as JSONSchema[], s);
return this.buildEnum(s.anyOf as JSONSchema[]);
}

/**
Expand All @@ -257,7 +256,7 @@ export default class Rust extends CodeGen {
}

protected handleOneOf(s: JSONSchemaObject): TypeIntermediateRepresentation {
return this.buildEnum(s.oneOf as JSONSchema[], s);
return this.buildEnum(s.oneOf as JSONSchema[]);
}

protected handleConstantBool(s: JSONSchemaBoolean): TypeIntermediateRepresentation {
Expand All @@ -270,11 +269,10 @@ export default class Rust extends CodeGen {
return { documentationComment: this.buildDocs(s), prefix: "type", typing: "serde_json::Value" };
}

private buildEnum(s: JSONSchema[], parentSchema: JSONSchemaObject): TypeIntermediateRepresentation {
private buildEnum(s: JSONSchema[]): TypeIntermediateRepresentation {
const typeLines = s
.map((enumItem) => {
const refTitle = this.refToTitle(enumItem);
let typeName = this.getSafeTitle(refTitle);
let typeName = this.getSafeTitle(this.refToTitle(enumItem));
let rhsTypeName = typeName;
if (enumItem !== false && enumItem !== true && enumItem.isCycle) {
rhsTypeName = `Box<${typeName}>`;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class Transpiler {
const reffed = schemaWithTitles.map(referencer);
const reffedAndCycleMarked = reffed.map((s) => setIsCycle(s, cycleMap));
if (useMerge) {
this.megaSchema = combineSchemas(reffed);
this.megaSchema = combineSchemas(reffedAndCycleMarked);
} else {
[this.megaSchema] = reffed;
[this.megaSchema] = reffedAndCycleMarked;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import deburr from "lodash.deburr";
import trim from "lodash.trim";
import { JSONSchema, Properties, JSONSchemaObject } from "@json-schema-tools/meta-schema";
import traverse from "@json-schema-tools/traverse";
import Dereferencer from "@json-schema-tools/dereferencer";
import referencer from "@json-schema-tools/referencer";

/**
* Capitalize the first letter of the string.
Expand Down

0 comments on commit 9d0ef32

Please sign in to comment.