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
2 changes: 1 addition & 1 deletion .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- golang,schema-golang
- cjson,schema-cjson
- cjson-default,cjson-multi-header,cjson-multi-split
- cplusplus,schema-cplusplus
- cplusplus,schema-cplusplus,schema-cplusplus-upper-acronyms
- flow,schema-flow
- java,schema-java
- python,schema-python
Expand Down
5 changes: 4 additions & 1 deletion packages/quicktype-core/src/support/Strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,13 @@ export function makeNameStyle(

switch (namingStyle) {
case "pascal":
case "pascal-upper-acronyms":
firstWordAcronymStyle = firstUpperWordStyle;
firstWordStyle = firstWordAcronymStyle;
break;
case "pascal-upper-acronyms":
firstWordStyle = firstUpperWordStyle;
firstWordAcronymStyle = allUpperWordStyle;
break;
case "camel":
case "camel-upper-acronyms":
firstWordAcronymStyle = allLowerWordStyle;
Expand Down
23 changes: 23 additions & 0 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,28 @@ class JSONSchemaFixture extends LanguageFixture {
}
}

class CPlusPlusUpperAcronymsFixture extends JSONSchemaFixture {
constructor() {
super(
languages.CPlusPlusUpperAcronymsLanguage,
"schema-cplusplus-upper-acronyms",
);
}

runForName(name: string): boolean {
return this.name === name;
}

getSamples(sources: string[]): { priority: Sample[]; others: Sample[] } {
return samplesFromSources(
sources,
["test/inputs/schema/upper-acronym-names.schema"],
[],
"schema",
);
}
}

// `leadingComments` is a quicktype-core API option, so the CLI fixture path
// cannot exercise it.
class LeadingCommentsGoFixture extends JSONSchemaFixture {
Expand Down Expand Up @@ -1809,6 +1831,7 @@ export const allFixtures: Fixture[] = [
new LeadingCommentsGoFixture(),
new JSONSchemaFixture(languages.CJSONLanguage),
new JSONSchemaFixture(languages.CPlusPlusLanguage),
new CPlusPlusUpperAcronymsFixture(),
new JSONSchemaFixture(languages.RustLanguage),
new JSONSchemaFixture(languages.RubyLanguage),
new JSONSchemaFixture(languages.PythonLanguage),
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/cplusplus/acronym_names.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "quicktype.hpp"

void use_upper_acronym_names(
quicktype::SCUBAWaypoint *,
quicktype::SCUBAManeuver *,
quicktype::IDCardHTTP *) {}
15 changes: 15 additions & 0 deletions test/inputs/schema/upper-acronym-names.1.fail.enum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"waypoints": [
{
"location": {
"latitude": 43.0,
"longitude": 16.0
},
"depth": 12.5,
"maneuver": "BACKFLIP",
"idCard": {
"value": "HTTP"
}
}
]
}
15 changes: 15 additions & 0 deletions test/inputs/schema/upper-acronym-names.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"waypoints": [
{
"location": {
"latitude": 43.0,
"longitude": 16.0
},
"depth": 12.5,
"maneuver": "LEVEL",
"idCard": {
"value": "HTTP"
}
}
]
}
37 changes: 37 additions & 0 deletions test/inputs/schema/upper-acronym-names.schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "A SCUBA dive log with waypoints",
"type": "object",
"properties": {
"waypoints": {
"type": "array",
"items": {
"title": "SCUBAWaypoint",
"type": "object",
"properties": {
"location": {
"title": "Point",
"type": "object",
"properties": {
"latitude": { "type": "number" },
"longitude": { "type": "number" }
}
},
"depth": { "type": "number" },
"maneuver": {
"title": "SCUBAManeuver",
"type": "string",
"enum": ["ASCENT", "DESCENT", "LEVEL"]
},
"idCard": {
"title": "IDCardHTTP",
"type": "object",
"properties": {
"value": { "type": "string" }
}
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions test/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const skipsEnumValueValidation = [
"enum-large.schema",
"optional-enum.schema",
"const-non-string.schema",
"upper-acronym-names.schema",
"haskell-enum-forbidden.schema",
"nullable-optional-one-of.schema",
"all-of-additional-properties-false.schema",
Expand Down Expand Up @@ -854,6 +855,16 @@ export const CPlusPlusLanguage: Language = {
sourceFiles: ["src/language/CPlusPlus/index.ts"],
};

export const CPlusPlusUpperAcronymsLanguage: Language = {
...CPlusPlusLanguage,
compileCommand:
"g++ -O0 -o quicktype -std=c++17 main.cpp acronym_names.cpp",
rendererOptions: {
"type-style": "pascal-case-upper-acronyms",
"member-style": "camel-case-upper-acronyms",
},
};

export const CPlusPlusMultiSourceLanguage: Language = {
...CPlusPlusLanguage,
includeJSON: ["pokedex.json"],
Expand Down
Loading