Skip to content

Conversation

@perher
Copy link
Contributor

@perher perher commented Jul 4, 2025

Fix support for generating go types for schemas using "nested ref definitions", i.e. types that only has allOf, anyOf, oneOf without any properties.

Example schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "anyOf": [
    {
      "$ref": "#/definitions/Policy"
    }
  ],
  "definitions": {
    "Policy": {
      "oneOf": [
        {
          "$ref": "#/definitions/Offer"
        }
      ]
    },
    "Offer": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}

without proposed fix the generator would fail with

Could not resolve ref "#/definitions/Policy": cannot resolve reference: expected named type: got *codegen.EmptyInterfaceType
    generation_test.go:261: could not merge anyOf types: types list is empty

also added a new test case to capture this

@codecov
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@29f8c48). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #458   +/-   ##
=======================================
  Coverage        ?   42.10%           
=======================================
  Files           ?       61           
  Lines           ?     6602           
  Branches        ?        0           
=======================================
  Hits            ?     2780           
  Misses          ?     3549           
  Partials        ?      273           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@omissis omissis force-pushed the nested-definitions branch from 53f05ff to 4543722 Compare October 18, 2025 15:19
@omissis omissis added this to the v0.21.0 milestone Oct 18, 2025
@omissis omissis merged commit b9a4d3b into omissis:main Oct 18, 2025
3 checks passed
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.

2 participants