Skip to content
Draft
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- JSON Schema `pattern` violation reasons are now identical in every target:
`must match pattern "^[a-z]+$", got "AB1"`, with the authored pattern (not
Java's and Python's `$`→`\z` / `\Z` end-anchor rewrite) and the offending
value each quoted as a JSON string. Java previously printed both bare and Go
quoted with `%q`. A `propertyNames` pattern failure reads
`invalid property name "Bad": must match pattern "^[a-z]+$"` everywhere
(Java dropped the prefix and TypeScript appended `, got …`), and every
`invalid property name` prefix now JSON-quotes the key. Generated Java
`Violation` gains a public `quote(String)` helper.
- Operation-free WIT interfaces now honor `@nexus.namespace`, and .NET names
their namespace after the interface (`Nexgen.<InterfaceName>`) instead of
falling back to `Nexgen.Generated`.
Expand Down
34 changes: 34 additions & 0 deletions advanced/samples/go/json_schema/api/chat/definitions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions advanced/samples/go/json_schema/api/kb/definitions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions advanced/samples/go/json_schema/api/showcase/definitions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions advanced/samples/go/json_schema/api/showcase/showcase.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions advanced/samples/go/json_schema/api/temporal/definitions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ public static String memberPath(String key) {
return "[\"" + key.replace("\\", "\\\\").replace("\"", "\\\"") + "\"]";
}

/** Quotes {@code value} as a JSON string literal for a violation reason. */
public static String quote(String value) {
StringBuilder out = new StringBuilder(value.length() + 2).append('"');
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '"') {
out.append("\\\"");
} else if (c == '\\') {
out.append("\\\\");
} else if (c == '\b') {
out.append("\\b");
} else if (c == '\f') {
out.append("\\f");
} else if (c == '\n') {
out.append("\\n");
} else if (c == '\r') {
out.append("\\r");
} else if (c == '\t') {
out.append("\\t");
} else if (c < 0x20) {
out.append(String.format("\\u%04x", (int) c));
} else {
out.append(c);
}
}
return out.append('"').toString();
}

public Violation withPathPrefix(String prefix) {
if (path == null || path.isEmpty()) {
return new Violation(prefix, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ public static String memberPath(String key) {
return "[\"" + key.replace("\\", "\\\\").replace("\"", "\\\"") + "\"]";
}

/** Quotes {@code value} as a JSON string literal for a violation reason. */
public static String quote(String value) {
StringBuilder out = new StringBuilder(value.length() + 2).append('"');
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '"') {
out.append("\\\"");
} else if (c == '\\') {
out.append("\\\\");
} else if (c == '\b') {
out.append("\\b");
} else if (c == '\f') {
out.append("\\f");
} else if (c == '\n') {
out.append("\\n");
} else if (c == '\r') {
out.append("\\r");
} else if (c == '\t') {
out.append("\\t");
} else if (c < 0x20) {
out.append(String.format("\\u%04x", (int) c));
} else {
out.append(c);
}
}
return out.append('"').toString();
}

public Violation withPathPrefix(String prefix) {
if (path == null || path.isEmpty()) {
return new Violation(prefix, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void serialize(Attributes value, JsonGenerator gen, SerializerProvider se
for (String pnKey : value.additionalProperties.keySet()) {
int pnLength = pnKey.codePointCount(0, pnKey.length());
if (pnLength > 8) {
violations.add(new Violation(Violation.memberPath(pnKey), "invalid property name \"" + pnKey + "\": must have length <= 8, got " + pnLength));
violations.add(new Violation(Violation.memberPath(pnKey), "invalid property name " + Violation.quote(pnKey) + ": must have length <= 8, got " + pnLength));
}
}
for (Map.Entry<String, String> entry : value.additionalProperties.entrySet()) {
Expand Down Expand Up @@ -138,7 +138,7 @@ public Attributes deserialize(JsonParser parser, DeserializationContext context)
String pnKey = propertyNameKeys.next();
int pnLength = pnKey.codePointCount(0, pnKey.length());
if (pnLength > 8) {
violations.add(new Violation(Violation.memberPath(pnKey), "invalid property name \"" + pnKey + "\": must have length <= 8, got " + pnLength));
violations.add(new Violation(Violation.memberPath(pnKey), "invalid property name " + Violation.quote(pnKey) + ": must have length <= 8, got " + pnLength));
}
}
if (!violations.isEmpty()) {
Expand Down
Loading
Loading