Skip to content

fix: fix missing object in tags - #11

Merged
cowan-macady merged 1 commit into
masterfrom
fix-object
Sep 16, 2026
Merged

cowan-macady merged 1 commit into
masterfrom
fix-object

Conversation

@cowan-macady

@cowan-macady cowan-macady commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

implement ENG-9771

Pull request

What this PR does

Fixes swaggertype:"object" being emitted as type: string, and tightens the related example and text-encoding paths found while verifying the fix.

swaggertype tags (gen/schema.go)

  • object is now accepted, bare or with a value type, so json.RawMessage
    fields tagged swaggertype:"object" emit type: object.
  • The tag is parsed recursively like swag: object,<type> is a typed map,
    array,array,integer keeps both dimensions, unknown element names degrade
    to string instead of an empty type, and whitespace after the comma is
    tolerated.

Examples on object and array fields (gen/constrain.go)

  • JSON text in example/default on an object field decodes to an object
    instead of a quoted string.
  • JSON arrays are decoded whole rather than split on inner commas.
  • Numbers are kept as json.Number, so large integer ids do not round.
  • null, trailing garbage, and non-JSON text stay plain strings.

Text encoding (gen/yaml.go, gen/emit.go)

  • &, <, > are written literally in both YAML and JSON, through one
    shared encoder helper, so the two formats no longer diverge.
  • YAML escapes DEL, the C1 range, and U+FFFE/U+FFFF, which strict loaders
    reject raw.

Verification

  • go test -race ./..., go vet, and golangci-lint are clean.
  • Regenerated all six jarvis-proto services: the only change is the one-line
    string to object fix in themis. oasparity passes, every YAML file is
    semantically equal to its JSON twin, and redocly validates all six.

Effect on annotations and output

How it was tested

  • make test passes
  • make lint passes
  • Tests added/updated for the new behavior (positive case + edge case)
  • make parity run (if output-affecting) — repo and result:

Known gaps or follow-ups

Copilot AI lite review requested due to automatic review settings September 16, 2026 17:20
@cowan-macady
cowan-macady requested a review from a team as a code owner September 16, 2026 17:20
@deepsource-io

deepsource-io Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in d1ed98c...8b50619 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Sep 16, 2026 5:52p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The structured-example decoder still accepts certain trailing JSON garbage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes swaggertype:"object" generation and improves structured example decoding and JSON/YAML escaping.

Changes:

  • Adds recursive object and array swaggertype parsing.
  • Preserves structured examples and large numbers.
  • Aligns JSON/YAML escaping and expands test coverage.
File summaries
File Changes and review notes
testdata/sample.go Adds a json.RawMessage object fixture.
gen/yaml.go Escapes YAML-invalid control characters and shared entities.
gen/schema.go Implements recursive swaggertype parsing.
gen/internal_test.go Adds unit coverage for coercion and encoding behavior.
gen/gen_test.go Adds integration coverage for generated object schemas.
gen/emit.go Adds shared JSON encoding. Nit (1 vote): the helper comment reverses the documented default behavior.
gen/constrain.go Decodes structured examples and defaults. Moderate issue (3 votes): trailing JSON garbage with stray closing delimiters can be accepted.
Review details

Suppressed comments (1)

gen/emit.go:96

  • This comment reverses the behavior being documented: the default json.MarshalIndent HTML-escapes & as \u0026, it does not write the literal &. As written, it can mislead callers about why this helper changes the JSON encoding policy.
// json.MarshalIndent would write "a=1&b=2"). A consumer that inlines
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gen/constrain.go Outdated
implement [ENG-9771]

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Only a non-blocking documentation nit remains.

Review details

Suppressed comments (1)

gen/emit.go:96

  • The encoding/json default used by json.MarshalIndent HTML-escapes & as \u0026, so this example currently describes the opposite of the behavior being replaced. Please correct the comment to show the escaped form (for example, "a=1\\u0026b=2") so callers are not misled about the compatibility change.
// json.MarshalIndent would write "a=1&b=2"). A consumer that inlines
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@cowan-macady
cowan-macady merged commit db4763d into master Sep 16, 2026
9 checks passed
@cowan-macady
cowan-macady deleted the fix-object branch September 16, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants