GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Generating strict servers using 2.1.0 breaks casting of imported components when moving from 2.0.0. · Issue #2010 · oapi-codegen/oapi-codegen

Generating strict servers using 2.1.0 breaks casting of imported components when moving from 2.0.0. #2010

New issue
Copy link
New issue
Copy link
Closed
Bug
#2357
Closed
Generating strict servers using 2.1.0 breaks casting of imported components when moving from 2.0.0.#2010
Bug
#2357
Copy link
Labels
bugSomething isn't workingSomething isn't working
Milestone
v2.7.0

Description

@MathewSharff
MathewSharff
opened on Jun 24, 2025
Issue body actions

Example code that breaks when generating using 2.1.0+:

package main

import (
	"fmt"

	"github.com/oapiexample/api"
	"github.com/oapiexample/otherapi"
)

func main() {
	var a api.GetExampleResponseObject

	var b otherapi.GetOtherExample400JSONResponse
	switch a.(type) {
	case api.GetExample400JSONResponse:
		b = otherapi.GetOtherExample400JSONResponse(a.(api.GetExample400JSONResponse)) // <- this line no longer compiles
	}

	fmt.Println(b.Message)
}

Setup:

open_api.yaml

openapi: 3.0.1
info:
  description: An example schema
  title: ExampleAPI
  version: 1.0.0
paths:
  /example:
    get:
      operationId: getExample
      responses:
        200:
          description: OK
        400:
          $ref: "#/components/responses/400"
components:
  responses:
    400:
      content:
        application/json:
          schema:
            properties:
              message:
                type: string
            required:
              - message
            type: object
      description: Bad Request

open_api.cfg.yaml

package: api
generate:
  chi-server: true
  models: true
  strict-server: true
output: ./api/api.go
output-options:
  skip-prune: true

open_api_other.yaml

openapi: 3.0.1
info:
  description: Another example schema
  title: OtherAPI
  version: 1.0.0
paths:
  /example:
    get:
      operationId: getOtherExample
      responses:
        200:
          description: OK
        400:
          $ref: "./open_api.yaml#/components/responses/400"

open_api_other.cfg.yaml

package: otherapi
generate:
  chi-server: true
  models: true
  strict-server: true
import-mapping:
  ./open_api.yaml: github.com/oapiexample/api/api
output: ./otherapi/api.go

generate.go

package oapiexample

//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/[email protected] --config open_api.cfg.yaml ./open_api.yaml
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/[email protected] --config open_api_other.cfg.yaml ./open_api_other.yaml

When I look at the generated code, this line changes from

type GetOtherExample400JSONResponse struct{ externalRef0.N400JSONResponse }

to

type GetOtherExample400JSONResponse struct{ externalRef0.N400 }

The GetExample400JSONResponse type that references the same response component continues to embed the N400JSONResponse type.

type GetExample400JSONResponse struct{ N400JSONResponse }

I believe pull request #1387 introduced this change.

Activity

  1. jamietanna
    added the
    Bug
    issue type on Jul 16, 2025
  2. jamietanna
    added
    bugSomething isn't workingSomething isn't working
    on Jul 16, 2025
  3. jamietanna
    added this to the v2.6.0 milestone on Jul 16, 2025
  4. mromaszewicz commented on Apr 22, 2026

    @mromaszewicz
    mromaszewicz
    on Apr 22, 2026
    Member
    More actions

    Man, this is a hard one.

    The issue is that we generate models separately from the strict server wrappers, and we have no knowledge about whether the external spec generated strict server models.

    To date, all the code I've written assumed that the external spec was mainly used for models, and I never planned for having external refs be used so deeply, so the code isn't fully tested.

    In this case, my preference would be for the strict server wrappers to only embed something that comes from the models generation option, and not from other strict servers, however, this is a pretty large change which would need to be gated behind an opt-in flag, and until I attempt it, I don't know how it would break.

    Another option might be to revert what #1387 did, and document a limitation - in that if you're generating strict servers, and importing request/response models across module boundaries, the external package must have been generated with the strict server option.

  5. mromaszewicz
    added 3 commits that reference this issue on Apr 30, 2026

    Overhaul anonymous schema hoisting

    2c70d80

    Overhaul anonymous schema hoisting

    8a21753

    Overhaul anonymous schema hoisting (#2348)

    81b9d95
  6. jamietanna commented on Apr 30, 2026

    @jamietanna
    jamietanna
    on Apr 30, 2026
    Member
    More actions

    I can't remember if #1387 was something that was actively stopping progression on #1378 which was functionality that we wanted to fix

    I think if we can see if reverting #1387 in a reasonable way without breaking too much other stuff would be fine - especially if the fix in #1387 fix is actually causing more of an issue

  7. mromaszewicz
    added a commit that references this issue on Apr 30, 2026

    revert external-ref carve-out in strict-server response embedding (#2010

    fbc8e0d
  8. mromaszewicz
    closed this as completedin #2357on Apr 30, 2026
  9. Boulea7
    added a commit that references this issue on Sep 28, 2026

    test: describe what the response_cast fixture now covers

    9228530
  10. mromaszewicz
    added a commit that references this issue on Sep 28, 2026

    fix: handle untyped strict response bodies (#2514)

    ddbdf0e
  11. Shaun1
    added a commit that references this issue on Oct 24, 2026

    feat!: replace std-http-server and strict-server with one server option

    ec52f6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    Bug

    Projects

    No projects

      Milestone

      • v2.7.0No due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.