Skip to content

Inline Bundling doesn't seem to work #511

@dpozinen

Description

@dpozinen

According to the docs:

Inlined bundling will perform the role of a ‘resolver’ and will extract every reference and replace every $ref with the concrete data referenced. This means every reference will have the same copy of data inlined where the reference once stood.

testSchema := `openapi: 3.0.4
info:
  title: Simple Test Schema
  version: 1.0.0
components:
  schemas:
    Person:
      type: object
      properties:
        name:
          type: string
        address:
          $ref: '#/components/schemas/Address'

    Address:
      type: object
      properties:
        street:
          type: string
        city:
          type: string
`

	specBytes := []byte(testSchema)

	doc, err := libopenapi.NewDocumentWithConfiguration(specBytes, &datamodel.DocumentConfiguration{
		BundleInlineRefs:        true,
		ExtractRefsSequentially: true,
		Logger: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
			Level: slog.LevelWarn,
		})),
	})

	v3Doc, errs := doc.BuildV3Model()
        // ...
	bundledBytes, err := bundler.BundleDocumentWithConfig(&v3Doc.Model,
		&bundler.BundleInlineConfig{ResolveDiscriminatorExternalRefs: true},
	)
	bundledBytes, err := v3Doc.Model.RenderJSON("  ")

	resultStr := string(bundledBytes)
	print(resultStr)

	var result map[string]interface{}
	if err := yaml.Unmarshal(bundledBytes, &result); err != nil {
		log.Fatalf("Failed to parse bundled result: %v", err)
	}
        // ...

My expectation is that the spec would transform into:

testSchema := `openapi: 3.0.4
info:
  title: Simple Test Schema
  version: 1.0.0
components:
  schemas:
    Person:
      type: object
      properties:
        name:
          type: string
        address:
            type: object
            properties:
              street:
                type: string
              city:
                type: string

But it is left intact basically. Sorry if I'm missing something obvious here, this is more of a question type issue maybe, but stackoverflow is dead, so here we are?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions