Repository: ogen-go/ogen
Pull request #145 (2022-01-31 07:47:30)

fix(gen): handle case when one variant has no unique fields


Patch:
diff --git a/examples/ex_github/oas_client_gen.go b/examples/ex_github/oas_client_gen.go
index f46c713a..ea9cf7fa 100644
--- a/examples/ex_github/oas_client_gen.go
+++ b/examples/ex_github/oas_client_gen.go
@@ -66675,6 +66675,121 @@ func (c *Client) UsersFollow(ctx context.Context, params UsersFollowParams) (res
 	return result, nil
 }
 
+// UsersGetAuthenticated invokes users/get-authenticated operation.
+//
+// If the authenticated user is authenticated through basic authentication or OAuth with the `user`
+// scope, then the response lists public and private profile information.
+// If the authenticated user is authenticated through OAuth without the `user` scope, then the
+// response lists only public profile information.
+//
+// GET /user
+func (c *Client) UsersGetAuthenticated(ctx context.Context) (res UsersGetAuthenticatedRes, err error) {
+	startTime := time.Now()
+	ctx, span := c.cfg.Tracer.Start(ctx, `UsersGetAuthenticated`,
+		trace.WithAttributes(otelogen.OperationID(`users/get-authenticated`)),
+		trace.WithSpanKind(trace.SpanKindClient),
+	)
+	defer func() {
+		if err != nil {
+			span.RecordError(err)
+			c.errors.Add(ctx, 1)
+		} else {
+			elapsedDuration := time.Since(startTime)
+			c.duration.Record(ctx, elapsedDuration.Microseconds())
+		}
+		span.End()
+	}()
+	c.requests.Add(ctx, 1)
+	u := uri.Clone(c.serverURL)
+	u.Path += "/user"
+
+	r := ht.NewRequest(ctx, "GET", u, nil)
+	defer ht.PutRequest(r)
+
+	resp, err := c.cfg.Client.Do(r)
+	if err != nil {
+		return res, errors.Wrap(err, "do request")
+	}
+	defer resp.Body.Close()
+
+	result, err := decodeUsersGetAuthenticatedResponse(resp, span)
+	if err != nil {
+		return res, errors.Wrap(err, "decode response")
+	}
+
+	return result, nil
+}
+
+// UsersGetByUsername invokes users/get-by-username operation.
+//
+// Provides publicly available information about someone with a GitHub account.
+// GitHub Apps with the `Plan` user permission can use this endpoint to retrieve information about a
+// user's GitHub plan. The GitHub App must be authenticated as a user. See "[Identifying and
+// authorizing users for GitHub Apps](https://docs.github.
+// com/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)" for details
+// about authentication. For an example response, see 'Response with GitHub plan information' below"
+// The `email` key in the following response is the publicly visible email address from your GitHub
+// [profile page](https://github.com/settings/profile). When setting up your profile, you can select
+// a primary email address to be “public” which provides an email entry for this endpoint. If you
+// do not set a public email address for `email`, then it will have a value of `null`. You only see
+// publicly visible email addresses when authenticated with GitHub. For more information, see
+// [Authentication](https://docs.github.com/rest/overview/resources-in-the-rest-api#authentication).
+// The Emails API enables you to list all of your email addresses, and toggle a primary email to be
+// visible publicly. For more information, see "[Emails API](https://docs.github.
+// com/rest/reference/users#emails)".
+//
+// GET /users/{username}
+func (c *Client) UsersGetByUsername(ctx context.Context, params UsersGetByUsernameParams) (res UsersGetByUsernameRes, err error) {
+	startTime := time.Now()
+	ctx, span := c.cfg.Tracer.Start(ctx, `UsersGetByUsername`,
+		trace.WithAttributes(otelogen.OperationID(`users/get-by-username`)),
+		trace.WithSpanKind(trace.SpanKindClient),
+	)
+	defer func() {
+		if err != nil {
+			span.RecordError(err)
+			c.errors.Add(ctx, 1)
+		} else {
+			elapsedDuration := time.Since(startTime)
+			c.duration.Record(ctx, elapsedDuration.Microseconds())
+		}
+		span.End()
+	}()
+	c.requests.Add(ctx, 1)
+	u := uri.Clone(c.serverURL)
+	u.Path += "/users/"
+	{
+		// Encode "username" parameter.
+		e := uri.NewPathEncoder(uri.PathEncoderConfig{
+			Param:   "username",
+			Style:   uri.PathStyleSimple,
+			Explode: false,
+		})
+		if err := func() error {
+			return e.EncodeValue(conv.StringToString(params.Username))
+		}(); err != nil {
+			return res, errors.Wrap(err, "encode path")
+		}
+		u.Path += e.Result()
+	}
+
+	r := ht.NewRequest(ctx, "GET", u, nil)
+	defer ht.PutRequest(r)
+
+	resp, err := c.cfg.Client.Do(r)
+	if err != nil {
+		return res, errors.Wrap(err, "do request")
+	}
+	defer resp.Body.Close()
+
+	result, err := decodeUsersGetByUsernameResponse(resp, span)
+	if err != nil {
+		return res, errors.Wrap(err, "decode response")
+	}
+
+	return result, nil
+}
+
 // UsersGetContextForUser invokes users/get-context-for-user operation.
 //
 // Provides hovercard information when authenticated through basic auth or OAuth with the `repo`
diff --git a/examples/ex_github/oas_handlers_gen.go b/examples/ex_github/oas_handlers_gen.go
index 6236733f..1251a677 100644
--- a/examples/ex_github/oas_handlers_gen.go
+++ b/examples/ex_github/oas_handlers_gen.go
@@ -21341,6 +21341,58 @@ func (s *Server) handleUsersFollowRequest(args [1]string, w http.ResponseWriter,
 	}
 }
 
+// HandleUsersGetAuthenticatedRequest handles users/get-authenticated operation.
+//
+// GET /user
+func (s *Server) handleUsersGetAuthenticatedRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
+	ctx, span := s.cfg.Tracer.Start(r.Context(), `UsersGetAuthenticated`,
+		trace.WithAttributes(otelogen.OperationID(`users/get-authenticated`)),
+		trace.WithSpanKind(trace.SpanKindServer),
+	)
+	defer span.End()
+
+	response, err := s.h.UsersGetAuthenticated(ctx)
+	if err != nil {
+		span.RecordError(err)
+		respondError(w, http.StatusInternalServerError, err)
+		return
+	}
+
+	if err := encodeUsersGetAuthenticatedResponse(response, w, span); err != nil {
+		span.RecordError(err)
+		return
+	}
+}
+
+// HandleUsersGetByUsernameRequest handles users/get-by-username operation.
+//
+// GET /users/{username}
+func (s *Server) handleUsersGetByUsernameRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
+	ctx, span := s.cfg.Tracer.Start(r.Context(), `UsersGetByUsername`,
+		trace.WithAttributes(otelogen.OperationID(`users/get-by-username`)),
+		trace.WithSpanKind(trace.SpanKindServer),
+	)
+	defer span.End()
+	params, err := decodeUsersGetByUsernameParams(args, r)
+	if err != nil {
+		span.RecordError(err)
+		respondError(w, http.StatusBadRequest, err)
+		return
+	}
+
+	response, err := s.h.UsersGetByUsername(ctx, params)
+	if err != nil {
+		span.RecordError(err)
+		respondError(w, http.StatusInternalServerError, err)
+		return
+	}
+
+	if err := encodeUsersGetByUsernameResponse(response, w, span); err != nil {
+		span.RecordError(err)
+		return
+	}
+}
+
 // HandleUsersGetContextForUserRequest handles users/get-context-for-user operation.
 //
 // GET /users/{username}/hovercard
diff --git a/examples/ex_github/oas_interfaces_gen.go b/examples/ex_github/oas_interfaces_gen.go
index 808c3bca..d5d2648a 100644
--- a/examples/ex_github/oas_interfaces_gen.go
+++ b/examples/ex_github/oas_interfaces_gen.go
@@ -1709,6 +1709,14 @@ type UsersFollowRes interface {
 	usersFollowRes()
 }
 
+type UsersGetAuthenticatedRes interface {
+	usersGetAuthenticatedRes()
+}
+
+type UsersGetByUsernameRes interface {
+	usersGetByUsernameRes()
+}
+
 type UsersGetContextForUserRes interface {
 	usersGetContextForUserRes()
 }
diff --git a/examples/ex_github/oas_json_gen.go b/examples/ex_github/oas_json_gen.go
index 978151cf..5c745b5e 100644
--- a/examples/ex_github/oas_json_gen.go
+++ b/examples/ex_github/oas_json_gen.go
@@ -90826,6 +90826,7 @@ func (s *ProjectsCreateCardReq) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -146445,6 +146446,174 @@ func (s *UsersFollowApplicationJSONUnauthorized) Decode(d *jx.Decoder) error {
 	return nil
 }
 
+// Encode encodes UsersGetAuthenticatedApplicationJSONForbidden as json.
+func (s UsersGetAuthenticatedApplicationJSONForbidden) Encode(e *jx.Writer) {
+	unwrapped := BasicError(s)
+	unwrapped.Encode(e)
+}
+
+// Decode decodes UsersGetAuthenticatedApplicationJSONForbidden from json.
+func (s *UsersGetAuthenticatedApplicationJSONForbidden) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode UsersGetAuthenticatedApplicationJSONForbidden to nil`)
+	}
+	var unwrapped BasicError
+	if err := func() error {
+		if err := unwrapped.Decode(d); err != nil {
+			return err
+		}
+		return nil
+	}(); err != nil {
+		return errors.Wrap(err, "alias")
+	}
+	*s = UsersGetAuthenticatedApplicationJSONForbidden(unwrapped)
+	return nil
+}
+
+// Encode encodes UsersGetAuthenticatedApplicationJSONUnauthorized as json.
+func (s UsersGetAuthenticatedApplicationJSONUnauthorized) Encode(e *jx.Writer) {
+	unwrapped := BasicError(s)
+	unwrapped.Encode(e)
+}
+
+// Decode decodes UsersGetAuthenticatedApplicationJSONUnauthorized from json.
+func (s *UsersGetAuthenticatedApplicationJSONUnauthorized) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode UsersGetAuthenticatedApplicationJSONUnauthorized to nil`)
+	}
+	var unwrapped BasicError
+	if err := func() error {
+		if err := unwrapped.Decode(d); err != nil {
+			return err
+		}
+		return nil
+	}(); err != nil {
+		return errors.Wrap(err, "alias")
+	}
+	*s = UsersGetAuthenticatedApplicationJSONUnauthorized(unwrapped)
+	return nil
+}
+
+// Encode encodes UsersGetAuthenticatedOK as json.
+func (s UsersGetAuthenticatedOK) Encode(e *jx.Writer) {
+	switch s.Type {
+	case PrivateUserUsersGetAuthenticatedOK:
+		s.PrivateUser.Encode(e)
+	case PublicUserUsersGetAuthenticatedOK:
+		s.PublicUser.Encode(e)
+	}
+}
+
+// Decode decodes UsersGetAuthenticatedOK from json.
+func (s *UsersGetAuthenticatedOK) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode UsersGetAuthenticatedOK to nil`)
+	}
+	// Sum type fields.
+	if d.Next() != jx.Object {
+		return errors.Errorf("unexpected json type %q", d.Next())
+	}
+
+	var found bool
+	if err := d.Capture(func(d *jx.Decoder) error {
+		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
+			if found {
+				return d.Skip()
+			}
+			switch string(key) {
+			case "two_factor_authentication":
+				found = true
+				s.Type = PrivateUserUsersGetAuthenticatedOK
+			case "business_plus":
+				found = true
+				s.Type = PrivateUserUsersGetAuthenticatedOK
+			case "ldap_dn":
+				found = true
+				s.Type = PrivateUserUsersGetAuthenticatedOK
+			}
+			return d.Skip()
+		})
+	}); err != nil {
+		return errors.Wrap(err, "capture")
+	}
+	if !found {
+		s.Type = PublicUserUsersGetAuthenticatedOK
+	}
+	switch s.Type {
+	case PrivateUserUsersGetAuthenticatedOK:
+		if err := s.PrivateUser.Decode(d); err != nil {
+			return err
+		}
+	case PublicUserUsersGetAuthenticatedOK:
+		if err := s.PublicUser.Decode(d); err != nil {
+			return err
+		}
+	default:
+		return errors.Errorf("inferred invalid type: %s", s.Type)
+	}
+	return nil
+}
+
+// Encode encodes UsersGetByUsernameOK as json.
+func (s UsersGetByUsernameOK) Encode(e *jx.Writer) {
+	switch s.Type {
+	case PrivateUserUsersGetByUsernameOK:
+		s.PrivateUser.Encode(e)
+	case PublicUserUsersGetByUsernameOK:
+		s.PublicUser.Encode(e)
+	}
+}
+
+// Decode decodes UsersGetByUsernameOK from json.
+func (s *UsersGetByUsernameOK) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode UsersGetByUsernameOK to nil`)
+	}
+	// Sum type fields.
+	if d.Next() != jx.Object {
+		return errors.Errorf("unexpected json type %q", d.Next())
+	}
+
+	var found bool
+	if err := d.Capture(func(d *jx.Decoder) error {
+		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
+			if found {
+				return d.Skip()
+			}
+			switch string(key) {
+			case "two_factor_authentication":
+				found = true
+				s.Type = PrivateUserUsersGetByUsernameOK
+			case "business_plus":
+				found = true
+				s.Type = PrivateUserUsersGetByUsernameOK
+			case "ldap_dn":
+				found = true
+				s.Type = PrivateUserUsersGetByUsernameOK
+			}
+			return d.Skip()
+		})
+	}); err != nil {
+		return errors.Wrap(err, "capture")
+	}
+	if !found {
+		s.Type = PublicUserUsersGetByUsernameOK
+	}
+	switch s.Type {
+	case PrivateUserUsersGetByUsernameOK:
+		if err := s.PrivateUser.Decode(d); err != nil {
+			return err
+		}
+	case PublicUserUsersGetByUsernameOK:
+		if err := s.PublicUser.Decode(d); err != nil {
+			return err
+		}
+	default:
+		return errors.Errorf("inferred invalid type: %s", s.Type)
+	}
+	return nil
+}
+
 // Encode encodes UsersGetGpgKeyForAuthenticatedApplicationJSONForbidden as json.
 func (s UsersGetGpgKeyForAuthenticatedApplicationJSONForbidden) Encode(e *jx.Writer) {
 	unwrapped := BasicError(s)
diff --git a/examples/ex_github/oas_param_dec_gen.go b/examples/ex_github/oas_param_dec_gen.go
index f5cc6d4c..a45c002c 100644
--- a/examples/ex_github/oas_param_dec_gen.go
+++ b/examples/ex_github/oas_param_dec_gen.go
@@ -69914,6 +69914,44 @@ func decodeUsersFollowParams(args [1]string, r *http.Request) (UsersFollowParams
 	return params, nil
 }
 
+func decodeUsersGetByUsernameParams(args [1]string, r *http.Request) (UsersGetByUsernameParams, error) {
+	var (
+		params UsersGetByUsernameParams
+	)
+	// Decode path: username.
+	{
+		param := args[0]
+		if len(param) > 0 {
+			d := uri.NewPathDecoder(uri.PathDecoderConfig{
+				Param:   "username",
+				Value:   param,
+				Style:   uri.PathStyleSimple,
+				Explode: false,
+			})
+
+			if err := func() error {
+				s, err := d.DecodeValue()
+				if err != nil {
+					return err
+				}
+
+				c, err := conv.ToString(s)
+				if err != nil {
+					return err
+				}
+
+				params.Username = c
+				return nil
+			}(); err != nil {
+				return params, err
+			}
+		} else {
+			return params, errors.New(`path: username: not specified`)
+		}
+	}
+	return params, nil
+}
+
 func decodeUsersGetContextForUserParams(args [1]string, r *http.Request) (UsersGetContextForUserParams, error) {
 	var (
 		params    UsersGetContextForUserParams
diff --git a/examples/ex_github/oas_param_gen.go b/examples/ex_github/oas_param_gen.go
index 7865bdee..92fecc9f 100644
--- a/examples/ex_github/oas_param_gen.go
+++ b/examples/ex_github/oas_param_gen.go
@@ -5336,6 +5336,10 @@ type UsersFollowParams struct {
 	Username string
 }
 
+type UsersGetByUsernameParams struct {
+	Username string
+}
+
 type UsersGetContextForUserParams struct {
 	Username string
 	// Identifies which additional information you'd like to receive about the person's hovercard. Can be
diff --git a/examples/ex_github/oas_res_dec_gen.go b/examples/ex_github/oas_res_dec_gen.go
index 8f0e8dfe..50826b24 100644
--- a/examples/ex_github/oas_res_dec_gen.go
+++ b/examples/ex_github/oas_res_dec_gen.go
@@ -44786,6 +44786,192 @@ func decodeUsersFollowResponse(resp *http.Response, span trace.Span) (res UsersF
 	}
 }
 
+func decodeUsersGetAuthenticatedResponse(resp *http.Response, span trace.Span) (res UsersGetAuthenticatedRes, err error) {
+	switch resp.StatusCode {
+	case 200:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response UsersGetAuthenticatedOK
+			if err := func() error {
+				if err := response.Decode(d); err != nil {
+					return err
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	case 304:
+		return &NotModified{}, nil
+	case 401:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response UsersGetAuthenticatedApplicationJSONUnauthorized
+			if err := func() error {
+				{
+					var unwrapped BasicError
+					if err := unwrapped.Decode(d); err != nil {
+						return err
+					}
+					response = UsersGetAuthenticatedApplicationJSONUnauthorized(unwrapped)
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	case 403:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response UsersGetAuthenticatedApplicationJSONForbidden
+			if err := func() error {
+				{
+					var unwrapped BasicError
+					if err := unwrapped.Decode(d); err != nil {
+						return err
+					}
+					response = UsersGetAuthenticatedApplicationJSONForbidden(unwrapped)
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	default:
+		return res, errors.Errorf("unexpected statusCode: %d", resp.StatusCode)
+	}
+}
+
+func decodeUsersGetByUsernameResponse(resp *http.Response, span trace.Span) (res UsersGetByUsernameRes, err error) {
+	switch resp.StatusCode {
+	case 200:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response UsersGetByUsernameOK
+			if err := func() error {
+				if err := response.Decode(d); err != nil {
+					return err
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	case 202:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response Accepted
+			if err := func() error {
+				if err := response.Decode(d); err != nil {
+					return err
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	case 404:
+		switch resp.Header.Get("Content-Type") {
+		case "application/json":
+			buf := getBuf()
+			defer putBuf(buf)
+			if _, err := io.Copy(buf, resp.Body); err != nil {
+				return res, err
+			}
+
+			d := jx.GetDecoder()
+			defer jx.PutDecoder(d)
+			d.ResetBytes(buf.Bytes())
+
+			var response BasicError
+			if err := func() error {
+				if err := response.Decode(d); err != nil {
+					return err
+				}
+				return nil
+			}(); err != nil {
+				return res, err
+			}
+
+			return &response, nil
+		default:
+			return res, errors.Errorf("unexpected content-type: %s", resp.Header.Get("Content-Type"))
+		}
+	default:
+		return res, errors.Errorf("unexpected statusCode: %d", resp.StatusCode)
+	}
+}
+
 func decodeUsersGetContextForUserResponse(resp *http.Response, span trace.Span) (res UsersGetContextForUserRes, err error) {
 	switch resp.StatusCode {
 	case 200:
diff --git a/examples/ex_github/oas_res_enc_gen.go b/examples/ex_github/oas_res_enc_gen.go
index addf18e4..350e85e3 100644
--- a/examples/ex_github/oas_res_enc_gen.go
+++ b/examples/ex_github/oas_res_enc_gen.go
@@ -21172,6 +21172,95 @@ func encodeUsersFollowResponse(response UsersFollowRes, w http.ResponseWriter, s
 	}
 }
 
+func encodeUsersGetAuthenticatedResponse(response UsersGetAuthenticatedRes, w http.ResponseWriter, span trace.Span) error {
+	switch response := response.(type) {
+	case *UsersGetAuthenticatedOK:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(200)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	case *NotModified:
+		w.WriteHeader(304)
+		return nil
+	case *UsersGetAuthenticatedApplicationJSONUnauthorized:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(401)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	case *UsersGetAuthenticatedApplicationJSONForbidden:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(403)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	default:
+		return errors.Errorf(`/user: unexpected response type: %T`, response)
+	}
+}
+
+func encodeUsersGetByUsernameResponse(response UsersGetByUsernameRes, w http.ResponseWriter, span trace.Span) error {
+	switch response := response.(type) {
+	case *UsersGetByUsernameOK:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(200)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	case *Accepted:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(202)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	case *BasicError:
+		w.Header().Set("Content-Type", "application/json")
+		w.WriteHeader(404)
+		e := jx.GetWriter()
+		defer jx.PutWriter(e)
+
+		response.Encode(e)
+		if _, err := e.WriteTo(w); err != nil {
+			return errors.Wrap(err, "write")
+		}
+
+		return nil
+	default:
+		return errors.Errorf(`/users/{username}: unexpected response type: %T`, response)
+	}
+}
+
 func encodeUsersGetContextForUserResponse(response UsersGetContextForUserRes, w http.ResponseWriter, span trace.Span) error {
 	switch response := response.(type) {
 	case *Hovercard:
diff --git a/examples/ex_github/oas_router_gen.go b/examples/ex_github/oas_router_gen.go
index 046e6078..75113d21 100644
--- a/examples/ex_github/oas_router_gen.go
+++ b/examples/ex_github/oas_router_gen.go
@@ -11614,9 +11614,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 				}
 
 				if len(elem) == 0 {
-					s.handleActivityListEventsForAuthenticatedUserRequest([1]string{
-						args[0],
-					}, w, r)
+					s.handleUsersGetAuthenticatedRequest([0]string{}, w, r)
 
 					return
 				}
@@ -12324,7 +12322,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 							elem = elem[idx:]
 
 							if len(elem) == 0 {
-								break
+								s.handleUsersGetByUsernameRequest([1]string{
+									args[0],
+								}, w, r)
+
+								return
 							}
 							switch elem[0] {
 							case '/': // Prefix: "/"
@@ -30221,7 +30223,7 @@ func (s *Server) FindRoute(method, path string) (r Route, _ bool) {
 				}
 
 				if len(elem) == 0 {
-					r.name = "ActivityListEventsForAuthenticatedUser"
+					r.name = "UsersGetAuthenticated"
 					r.args = args
 					r.count = 0
 					return r, true
@@ -30933,7 +30935,10 @@ func (s *Server) FindRoute(method, path string) (r Route, _ bool) {
 							elem = elem[idx:]
 
 							if len(elem) == 0 {
-								break
+								r.name = "UsersGetByUsername"
+								r.args = args
+								r.count = 1
+								return r, true
 							}
 							switch elem[0] {
 							case '/': // Prefix: "/"
diff --git a/examples/ex_github/oas_schemas_gen.go b/examples/ex_github/oas_schemas_gen.go
index 23cd3e14..ee75dcaa 100644
--- a/examples/ex_github/oas_schemas_gen.go
+++ b/examples/ex_github/oas_schemas_gen.go
@@ -98,6 +98,7 @@ func (*Accepted) reposGetCodeFrequencyStatsRes()    {}
 func (*Accepted) reposGetCommitActivityStatsRes()   {}
 func (*Accepted) reposGetContributorsStatsRes()     {}
 func (*Accepted) reposRedeliverWebhookDeliveryRes() {}
+func (*Accepted) usersGetByUsernameRes()            {}
 
 // ActionsAddRepoAccessToSelfHostedRunnerGroupInOrgNoContent is response for ActionsAddRepoAccessToSelfHostedRunnerGroupInOrg operation.
 type ActionsAddRepoAccessToSelfHostedRunnerGroupInOrgNoContent struct{}
@@ -2367,6 +2368,7 @@ func (*BasicError) teamsListProjectsLegacyRes()                          {}
 func (*BasicError) teamsListReposLegacyRes()                             {}
 func (*BasicError) teamsListRes()                                        {}
 func (*BasicError) teamsRemoveProjectLegacyRes()                         {}
+func (*BasicError) usersGetByUsernameRes()                               {}
 func (*BasicError) usersGetContextForUserRes()                           {}
 
 // Blob.
@@ -8964,6 +8966,7 @@ func (*NotModified) usersDeleteEmailForAuthenticatedRes()                  {}
 func (*NotModified) usersDeleteGpgKeyForAuthenticatedRes()                 {}
 func (*NotModified) usersDeletePublicSSHKeyForAuthenticatedRes()           {}
 func (*NotModified) usersFollowRes()                                       {}
+func (*NotModified) usersGetAuthenticatedRes()                             {}
 func (*NotModified) usersGetGpgKeyForAuthenticatedRes()                    {}
 func (*NotModified) usersGetPublicSSHKeyForAuthenticatedRes()              {}
 func (*NotModified) usersListBlockedByAuthenticatedRes()                   {}
@@ -39758,6 +39761,150 @@ type UsersFollowNoContent struct{}
 
 func (*UsersFollowNoContent) usersFollowRes() {}
 
+type UsersGetAuthenticatedApplicationJSONForbidden BasicError
+
+func (*UsersGetAuthenticatedApplicationJSONForbidden) usersGetAuthenticatedRes() {}
+
+type UsersGetAuthenticatedApplicationJSONUnauthorized BasicError
+
+func (*UsersGetAuthenticatedApplicationJSONUnauthorized) usersGetAuthenticatedRes() {}
+
+// UsersGetAuthenticatedOK represents sum type.
+type UsersGetAuthenticatedOK struct {
+	Type        UsersGetAuthenticatedOKType // switch on this field
+	PrivateUser PrivateUser
+	PublicUser  PublicUser
+}
+
+// UsersGetAuthenticatedOKType is oneOf type of UsersGetAuthenticatedOK.
+type UsersGetAuthenticatedOKType string
+
+// Possible values for UsersGetAuthenticatedOKType.
+const (
+	PrivateUserUsersGetAuthenticatedOK UsersGetAuthenticatedOKType = "PrivateUser"
+	PublicUserUsersGetAuthenticatedOK  UsersGetAuthenticatedOKType = "PublicUser"
+)
+
+// IsPrivateUser reports whether UsersGetAuthenticatedOK is PrivateUser.
+func (s UsersGetAuthenticatedOK) IsPrivateUser() bool {
+	return s.Type == PrivateUserUsersGetAuthenticatedOK
+}
+
+// IsPublicUser reports whether UsersGetAuthenticatedOK is PublicUser.
+func (s UsersGetAuthenticatedOK) IsPublicUser() bool {
+	return s.Type == PublicUserUsersGetAuthenticatedOK
+}
+
+// SetPrivateUser sets UsersGetAuthenticatedOK to PrivateUser.
+func (s *UsersGetAuthenticatedOK) SetPrivateUser(v PrivateUser) {
+	s.Type = PrivateUserUsersGetAuthenticatedOK
+	s.PrivateUser = v
+}
+
+// GetPrivateUser returns PrivateUser and true boolean if UsersGetAuthenticatedOK is PrivateUser.
+func (s UsersGetAuthenticatedOK) GetPrivateUser() (v PrivateUser, ok bool) {
+	if !s.IsPrivateUser() {
+		return v, false
+	}
+	return s.PrivateUser, true
+}
+
+// NewPrivateUserUsersGetAuthenticatedOK returns new UsersGetAuthenticatedOK from PrivateUser.
+func NewPrivateUserUsersGetAuthenticatedOK(v PrivateUser) UsersGetAuthenticatedOK {
+	var s UsersGetAuthenticatedOK
+	s.SetPrivateUser(v)
+	return s
+}
+
+// SetPublicUser sets UsersGetAuthenticatedOK to PublicUser.
+func (s *UsersGetAuthenticatedOK) SetPublicUser(v PublicUser) {
+	s.Type = PublicUserUsersGetAuthenticatedOK
+	s.PublicUser = v
+}
+
+// GetPublicUser returns PublicUser and true boolean if UsersGetAuthenticatedOK is PublicUser.
+func (s UsersGetAuthenticatedOK) GetPublicUser() (v PublicUser, ok bool) {
+	if !s.IsPublicUser() {
+		return v, false
+	}
+	return s.PublicUser, true
+}
+
+// NewPublicUserUsersGetAuthenticatedOK returns new UsersGetAuthenticatedOK from PublicUser.
+func NewPublicUserUsersGetAuthenticatedOK(v PublicUser) UsersGetAuthenticatedOK {
+	var s UsersGetAuthenticatedOK
+	s.SetPublicUser(v)
+	return s
+}
+
+func (*UsersGetAuthenticatedOK) usersGetAuthenticatedRes() {}
+
+// UsersGetByUsernameOK represents sum type.
+type UsersGetByUsernameOK struct {
+	Type        UsersGetByUsernameOKType // switch on this field
+	PrivateUser PrivateUser
+	PublicUser  PublicUser
+}
+
+// UsersGetByUsernameOKType is oneOf type of UsersGetByUsernameOK.
+type UsersGetByUsernameOKType string
+
+// Possible values for UsersGetByUsernameOKType.
+const (
+	PrivateUserUsersGetByUsernameOK UsersGetByUsernameOKType = "PrivateUser"
+	PublicUserUsersGetByUsernameOK  UsersGetByUsernameOKType = "PublicUser"
+)
+
+// IsPrivateUser reports whether UsersGetByUsernameOK is PrivateUser.
+func (s UsersGetByUsernameOK) IsPrivateUser() bool { return s.Type == PrivateUserUsersGetByUsernameOK }
+
+// IsPublicUser reports whether UsersGetByUsernameOK is PublicUser.
+func (s UsersGetByUsernameOK) IsPublicUser() bool { return s.Type == PublicUserUsersGetByUsernameOK }
+
+// SetPrivateUser sets UsersGetByUsernameOK to PrivateUser.
+func (s *UsersGetByUsernameOK) SetPrivateUser(v PrivateUser) {
+	s.Type = PrivateUserUsersGetByUsernameOK
+	s.PrivateUser = v
+}
+
+// GetPrivateUser returns PrivateUser and true boolean if UsersGetByUsernameOK is PrivateUser.
+func (s UsersGetByUsernameOK) GetPrivateUser() (v PrivateUser, ok bool) {
+	if !s.IsPrivateUser() {
+		return v, false
+	}
+	return s.PrivateUser, true
+}
+
+// NewPrivateUserUsersGetByUsernameOK returns new UsersGetByUsernameOK from PrivateUser.
+func NewPrivateUserUsersGetByUsernameOK(v PrivateUser) UsersGetByUsernameOK {
+	var s UsersGetByUsernameOK
+	s.SetPrivateUser(v)
+	return s
+}
+
+// SetPublicUser sets UsersGetByUsernameOK to PublicUser.
+func (s *UsersGetByUsernameOK) SetPublicUser(v PublicUser) {
+	s.Type = PublicUserUsersGetByUsernameOK
+	s.PublicUser = v
+}
+
+// GetPublicUser returns PublicUser and true boolean if UsersGetByUsernameOK is PublicUser.
+func (s UsersGetByUsernameOK) GetPublicUser() (v PublicUser, ok bool) {
+	if !s.IsPublicUser() {
+		return v, false
+	}
+	return s.PublicUser, true
+}
+
+// NewPublicUserUsersGetByUsernameOK returns new UsersGetByUsernameOK from PublicUser.
+func NewPublicUserUsersGetByUsernameOK(v PublicUser) UsersGetByUsernameOK {
+	var s UsersGetByUsernameOK
+	s.SetPublicUser(v)
+	return s
+}
+
+func (*UsersGetByUsernameOK) usersGetByUsernameRes() {}
+
 type UsersGetContextForUserSubjectType string
 
 const (
diff --git a/examples/ex_github/oas_server_gen.go b/examples/ex_github/oas_server_gen.go
index 282456ee..c881714b 100644
--- a/examples/ex_github/oas_server_gen.go
+++ b/examples/ex_github/oas_server_gen.go
@@ -7258,6 +7258,35 @@ type Handler interface {
 	//
 	// PUT /user/following/{username}
 	UsersFollow(ctx context.Context, params UsersFollowParams) (UsersFollowRes, error)
+	// UsersGetAuthenticated implements users/get-authenticated operation.
+	//
+	// If the authenticated user is authenticated through basic authentication or OAuth with the `user`
+	// scope, then the response lists public and private profile information.
+	// If the authenticated user is authenticated through OAuth without the `user` scope, then the
+	// response lists only public profile information.
+	//
+	// GET /user
+	UsersGetAuthenticated(ctx context.Context) (UsersGetAuthenticatedRes, error)
+	// UsersGetByUsername implements users/get-by-username operation.
+	//
+	// Provides publicly available information about someone with a GitHub account.
+	// GitHub Apps with the `Plan` user permission can use this endpoint to retrieve information about a
+	// user's GitHub plan. The GitHub App must be authenticated as a user. See "[Identifying and
+	// authorizing users for GitHub Apps](https://docs.github.
+	// com/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)" for details
+	// about authentication. For an example response, see 'Response with GitHub plan information' below"
+	// The `email` key in the following response is the publicly visible email address from your GitHub
+	// [profile page](https://github.com/settings/profile). When setting up your profile, you can select
+	// a primary email address to be “public” which provides an email entry for this endpoint. If you
+	// do not set a public email address for `email`, then it will have a value of `null`. You only see
+	// publicly visible email addresses when authenticated with GitHub. For more information, see
+	// [Authentication](https://docs.github.com/rest/overview/resources-in-the-rest-api#authentication).
+	// The Emails API enables you to list all of your email addresses, and toggle a primary email to be
+	// visible publicly. For more information, see "[Emails API](https://docs.github.
+	// com/rest/reference/users#emails)".
+	//
+	// GET /users/{username}
+	UsersGetByUsername(ctx context.Context, params UsersGetByUsernameParams) (UsersGetByUsernameRes, error)
 	// UsersGetContextForUser implements users/get-context-for-user operation.
 	//
 	// Provides hovercard information when authenticated through basic auth or OAuth with the `repo`
diff --git a/examples/ex_github/oas_validators_gen.go b/examples/ex_github/oas_validators_gen.go
index c21ba4e8..385816d4 100644
--- a/examples/ex_github/oas_validators_gen.go
+++ b/examples/ex_github/oas_validators_gen.go
@@ -15293,6 +15293,34 @@ func (s UsersDeleteEmailForAuthenticatedReq0) Validate() error {
 	}
 	return nil
 }
+func (s UsersGetAuthenticatedOK) Validate() error {
+	switch s.Type {
+	case PrivateUserUsersGetAuthenticatedOK:
+		if err := s.PrivateUser.Validate(); err != nil {
+			return err
+		}
+		return nil
+	case PublicUserUsersGetAuthenticatedOK:
+		return nil // no validation needed
+	default:
+		return errors.Errorf("invalid type %q", s.Type)
+	}
+}
+
+func (s UsersGetByUsernameOK) Validate() error {
+	switch s.Type {
+	case PrivateUserUsersGetByUsernameOK:
+		if err := s.PrivateUser.Validate(); err != nil {
+			return err
+		}
+		return nil
+	case PublicUserUsersGetByUsernameOK:
+		return nil // no validation needed
+	default:
+		return errors.Errorf("invalid type %q", s.Type)
+	}
+}
+
 func (s UsersGetContextForUserSubjectType) Validate() error {
 	switch s {
 	case "organization":
diff --git a/examples/ex_gotd/oas_json_gen.go b/examples/ex_gotd/oas_json_gen.go
index 2a261372..a5808044 100644
--- a/examples/ex_gotd/oas_json_gen.go
+++ b/examples/ex_gotd/oas_json_gen.go
@@ -1545,6 +1545,7 @@ func (s *BotCommandScope) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -3399,6 +3400,7 @@ func (s *CopyMessageReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -7894,6 +7896,7 @@ func (s *InputMedia) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -12804,6 +12807,7 @@ func (s *PassportElementError) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -16347,6 +16351,7 @@ func (s *SendAnimationReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -16705,6 +16710,7 @@ func (s *SendAudioReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -17076,6 +17082,7 @@ func (s *SendContactReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -17310,6 +17317,7 @@ func (s *SendDiceReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -17638,6 +17646,7 @@ func (s *SendDocumentReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -18591,6 +18600,7 @@ func (s *SendLocationReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -18827,6 +18837,7 @@ func (s *SendMediaGroupMediaItem) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -19129,6 +19140,7 @@ func (s *SendMessageReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -19427,6 +19439,7 @@ func (s *SendPhotoReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -19865,6 +19878,7 @@ func (s *SendPollReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -20098,6 +20112,7 @@ func (s *SendStickerReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -20434,6 +20449,7 @@ func (s *SendVenueReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -21006,6 +21022,7 @@ func (s *SendVideoNoteReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -21086,6 +21103,7 @@ func (s *SendVideoReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -21399,6 +21417,7 @@ func (s *SendVoiceReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
diff --git a/examples/ex_telegram/oas_json_gen.go b/examples/ex_telegram/oas_json_gen.go
index 6af9f5d2..131ef917 100644
--- a/examples/ex_telegram/oas_json_gen.go
+++ b/examples/ex_telegram/oas_json_gen.go
@@ -1632,6 +1632,7 @@ func (s *BotCommandScope) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -3347,6 +3348,7 @@ func (s *ChatMember) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -5355,6 +5357,7 @@ func (s *CopyMessageReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -10317,6 +10320,7 @@ func (s *InlineQueryResult) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -15957,6 +15961,7 @@ func (s *InputMedia) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -17073,6 +17078,7 @@ func (s *InputMessageContent) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -22063,6 +22069,7 @@ func (s *PassportElementError) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -27759,6 +27766,7 @@ func (s *SendAnimationReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -28117,6 +28125,7 @@ func (s *SendAudioReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -28488,6 +28497,7 @@ func (s *SendContactReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -28722,6 +28732,7 @@ func (s *SendDiceReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -29050,6 +29061,7 @@ func (s *SendDocumentReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -30003,6 +30015,7 @@ func (s *SendLocationReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -30239,6 +30252,7 @@ func (s *SendMediaGroupMediaItem) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -30541,6 +30555,7 @@ func (s *SendMessageReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -30839,6 +30854,7 @@ func (s *SendPhotoReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -31277,6 +31293,7 @@ func (s *SendPollReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -31510,6 +31527,7 @@ func (s *SendStickerReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -31846,6 +31864,7 @@ func (s *SendVenueReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -32418,6 +32437,7 @@ func (s *SendVideoNoteReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -32498,6 +32518,7 @@ func (s *SendVideoReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -32811,6 +32832,7 @@ func (s *SendVoiceReplyMarkup) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
diff --git a/gen/_template/json/encoders_sum.tmpl b/gen/_template/json/encoders_sum.tmpl
index 7560868b..b0a12710 100644
--- a/gen/_template/json/encoders_sum.tmpl
+++ b/gen/_template/json/encoders_sum.tmpl
@@ -31,6 +31,7 @@ func (s *{{ $.Name }}) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -70,7 +71,11 @@ func (s *{{ $.Name }}) Decode(d *jx.Decoder) error {
 		return errors.Wrap(err, "capture")
 	}
 	if !found {
+		{{- if $.SumSpec.DefaultMapping }}
+		s.Type = {{ $.SumSpec.DefaultMapping }}{{ $.Name }}
+		{{- else }}
 		return errors.New("unable to detect sum type variant")
+		{{- end }}
 	}
 	switch s.Type {
 	{{- range $s := $.SumOf }}
diff --git a/gen/schema_gen.go b/gen/schema_gen.go
index 5b005bf1..564c9574 100644
--- a/gen/schema_gen.go
+++ b/gen/schema_gen.go
@@ -307,6 +307,27 @@ func (g *schemaGen) generate(name string, schema *oas.Schema) (_ *ir.Type, err e
 					delete(uniq[variant.Name], field)
 				}
 			}
+
+			if isComplex {
+				// Check that at most one type has no unique fields.
+				metNoUniqueFields := false
+				for _, variant := range sum.SumOf {
+					k := variant.Name
+					if len(uniq[k]) == 0 {
+						if metNoUniqueFields {
+							// Unable to deterministically select sub-schema only on fields.
+							return nil, errors.Wrapf(&ErrNotImplemented{Name: "discriminator inference"},
+								"oneOf %s: variant %s: no unique fields, "+
+									"unable to parse without discriminator", sum.Name, k,
+							)
+						}
+
+						// Set mapping without unique fields as default
+						sum.SumSpec.DefaultMapping = k
+						metNoUniqueFields = true
+					}
+				}
+			}
 		}
 		type sumVariant struct {
 			Name   string
@@ -323,13 +344,6 @@ func (g *schemaGen) generate(name string, schema *oas.Schema) (_ *ir.Type, err e
 				v.Unique = append(v.Unique, fieldName)
 			}
 			sort.Strings(v.Unique)
-			if isComplex && len(v.Unique) == 0 {
-				// Unable to deterministically select sub-schema only on fields.
-				return nil, errors.Wrapf(&ErrNotImplemented{Name: "discriminator inference"},
-					"oneOf %s: variant %s: no unique fields, "+
-						"unable to parse without discriminator", sum.Name, k,
-				)
-			}
 			variants = append(variants, v)
 		}
 		sort.SliceStable(variants, func(i, j int) bool {
diff --git a/internal/ir/type.go b/internal/ir/type.go
index eb0d5686..4ef9b0f7 100644
--- a/internal/ir/type.go
+++ b/internal/ir/type.go
@@ -62,6 +62,11 @@ func (t *TypeDiscriminator) Set(s *Type) {
 // SumSpec for KindSum.
 type SumSpec struct {
 	Unique []*Field
+	// DefaultMapping is name of default mapping.
+	//
+	// Used for variant which has no unique fields.
+	DefaultMapping string
+
 	// Discriminator is field name of sum type discriminator.
 	Discriminator string
 	// Mapping is discriminator value -> variant mapping.
@@ -97,7 +102,7 @@ type Type struct {
 	//
 	// If some of these features are set, generator
 	// generates additional encoding methods if needed.
-	Features         []string
+	Features []string
 }
 
 func (t Type) GoDoc() []string {
diff --git a/internal/sample_api/oas_client_gen.go b/internal/sample_api/oas_client_gen.go
index cc8185c9..1842f39c 100644
--- a/internal/sample_api/oas_client_gen.go
+++ b/internal/sample_api/oas_client_gen.go
@@ -494,7 +494,7 @@ func (c *Client) GetHeader(ctx context.Context, params GetHeaderParams) (res Has
 // OneofBug invokes oneofBug operation.
 //
 // POST /oneofBug
-func (c *Client) OneofBug(ctx context.Context, request OneofBugReq) (res OneofBugOK, err error) {
+func (c *Client) OneofBug(ctx context.Context, request OneOfBugs) (res OneofBugOK, err error) {
 	startTime := time.Now()
 	ctx, span := c.cfg.Tracer.Start(ctx, `OneofBug`,
 		trace.WithAttributes(otelogen.OperationID(`oneofBug`)),
diff --git a/internal/sample_api/oas_json_gen.go b/internal/sample_api/oas_json_gen.go
index 46f3e1e3..0a11bc5f 100644
--- a/internal/sample_api/oas_json_gen.go
+++ b/internal/sample_api/oas_json_gen.go
@@ -441,6 +441,7 @@ func (s *DataDescription) Decode(d *jx.Decoder) error {
 	if d.Next() != jx.Object {
 		return errors.Errorf("unexpected json type %q", d.Next())
 	}
+
 	var found bool
 	if err := d.Capture(func(d *jx.Decoder) error {
 		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
@@ -902,115 +903,150 @@ func (s *ID) Decode(d *jx.Decoder) error {
 	return nil
 }
 
-// Encode implements json.Marshaler.
-func (s MapWithProperties) Encode(e *jx.Writer) {
-	e.ObjStart()
-	var (
-		first = true
-		_     = first
-	)
-	{
-		{
-			if !first {
-				e.Comma()
-			}
-			first = false
+// Encode encodes Issue143 as json.
+func (s Issue143) Encode(e *jx.Writer) {
+	switch s.Type {
+	case Issue1430Issue143:
+		s.Issue1430.Encode(e)
+	case Issue1431Issue143:
+		s.Issue1431.Encode(e)
+	case Issue1432Issue143:
+		s.Issue1432.Encode(e)
+	case Issue1433Issue143:
+		s.Issue1433.Encode(e)
+	}
+}
 
-			e.RawStr("\"required\"" + ":")
-			e.Int(s.Required)
-		}
-		{
-			if s.Optional.Set {
-				e.Comma()
+// Decode decodes Issue143 from json.
+func (s *Issue143) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode Issue143 to nil`)
+	}
+	// Sum type fields.
+	if d.Next() != jx.Object {
+		return errors.Errorf("unexpected json type %q", d.Next())
+	}
+
+	var found bool
+	if err := d.Capture(func(d *jx.Decoder) error {
+		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
+			if found {
+				return d.Skip()
 			}
-			if s.Optional.Set {
-				e.RawStr("\"optional\"" + ":")
-				s.Optional.Encode(e)
+			switch string(key) {
+			case "unique-1":
+				found = true
+				s.Type = Issue1430Issue143
+			case "unique-2":
+				found = true
+				s.Type = Issue1431Issue143
+			case "unique-3":
+				found = true
+				s.Type = Issue1432Issue143
+			case "unique-4":
+				found = true
+				s.Type = Issue1433Issue143
 			}
+			return d.Skip()
+		})
+	}); err != nil {
+		return errors.Wrap(err, "capture")
+	}
+	if !found {
+		return errors.New("unable to detect sum type variant")
+	}
+	switch s.Type {
+	case Issue1430Issue143:
+		if err := s.Issue1430.Decode(d); err != nil {
+			return err
 		}
-		{
-			if s.SubMap.Set {
-				e.Comma()
-			}
-			if s.SubMap.Set {
-				e.RawStr("\"sub_map\"" + ":")
-				s.SubMap.Encode(e)
-			}
+	case Issue1431Issue143:
+		if err := s.Issue1431.Decode(d); err != nil {
+			return err
 		}
-		{
-			if s.InlinedSubMap.Set {
-				e.Comma()
-			}
-			if s.InlinedSubMap.Set {
-				e.RawStr("\"inlined_sub_map\"" + ":")
-				s.InlinedSubMap.Encode(e)
-			}
+	case Issue1432Issue143:
+		if err := s.Issue1432.Decode(d); err != nil {
+			return err
+		}
+	case Issue1433Issue143:
+		if err := s.Issue1433.Decode(d); err != nil {
+			return err
 		}
+	default:
+		return errors.Errorf("inferred invalid type: %s", s.Type)
 	}
-	for k, elem := range s.AdditionalProps {
+	return nil
+}
+
+// Encode implements json.Marshaler.
+func (s Issue1430) Encode(e *jx.Writer) {
+	e.ObjStart()
+	var (
+		first = true
+		_     = first
+	)
+	{
 		if !first {
 			e.Comma()
 		}
-		first = true
-		e.Str(k)
-		e.RawStr(`:`)
+		first = false
 
-		e.Str(elem)
+		e.RawStr("\"common-1\"" + ":")
+		e.Str(s.CommonMinus1)
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"common-2\"" + ":")
+		e.Int(s.CommonMinus2)
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"unique-1\"" + ":")
+		e.Str(s.UniqueMinus1)
 	}
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfMapWithProperties = [4]string{
-	0: "required",
-	1: "optional",
-	2: "sub_map",
-	3: "inlined_sub_map",
+var jsonFieldsNameOfIssue1430 = [3]string{
+	0: "common-1",
+	1: "common-2",
+	2: "unique-1",
 }
 
-// Decode decodes MapWithProperties from json.
-func (s *MapWithProperties) Decode(d *jx.Decoder) error {
+// Decode decodes Issue1430 from json.
+func (s *Issue1430) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode MapWithProperties to nil`)
+		return errors.New(`invalid: unable to decode Issue1430 to nil`)
 	}
 	var requiredBitSet [1]uint8
 
-	m := s.AdditionalProps
-	if m == nil {
-		m = map[string]string{}
-		s.AdditionalProps = m
-	}
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		case "required":
+		case "common-1":
 			requiredBitSet[0] |= 1 << 0
-			v, err := d.Int()
-			s.Required = int(v)
+			v, err := d.Str()
+			s.CommonMinus1 = string(v)
 			if err != nil {
 				return err
 			}
-		case "optional":
-			s.Optional.Reset()
-			if err := s.Optional.Decode(d); err != nil {
-				return err
-			}
-		case "sub_map":
-			s.SubMap.Reset()
-			if err := s.SubMap.Decode(d); err != nil {
-				return err
-			}
-		case "inlined_sub_map":
-			s.InlinedSubMap.Reset()
-			if err := s.InlinedSubMap.Decode(d); err != nil {
+		case "common-2":
+			requiredBitSet[0] |= 1 << 1
+			v, err := d.Int()
+			s.CommonMinus2 = int(v)
+			if err != nil {
 				return err
 			}
-		default:
-			var elem string
+		case "unique-1":
+			requiredBitSet[0] |= 1 << 2
 			v, err := d.Str()
-			elem = string(v)
+			s.UniqueMinus1 = string(v)
 			if err != nil {
 				return err
 			}
-			m[string(k)] = elem
+		default:
+			return d.Skip()
 		}
 		return nil
 	}); err != nil {
@@ -1018,7 +1054,7 @@ func (s *MapWithProperties) Decode(d *jx.Decoder) error {
 	}
 	var failures []validate.FieldError
 	for i, mask := range [1]uint8{
-		0b00000001,
+		0b00000111,
 	} {
 		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
 			// Mask only required fields and check equality to mask using XOR.
@@ -1030,8 +1066,8 @@ func (s *MapWithProperties) Decode(d *jx.Decoder) error {
 				bitIdx := bits.TrailingZeros8(result)
 				fieldIdx := i*8 + bitIdx
 				var name string
-				if fieldIdx < len(jsonFieldsNameOfMapWithProperties) {
-					name = jsonFieldsNameOfMapWithProperties[fieldIdx]
+				if fieldIdx < len(jsonFieldsNameOfIssue1430) {
+					name = jsonFieldsNameOfIssue1430[fieldIdx]
 				} else {
 					name = strconv.Itoa(fieldIdx)
 				}
@@ -1052,63 +1088,544 @@ func (s *MapWithProperties) Decode(d *jx.Decoder) error {
 }
 
 // Encode implements json.Marshaler.
-func (s MapWithPropertiesInlinedSubMap) Encode(e *jx.Writer) {
+func (s Issue1431) Encode(e *jx.Writer) {
 	e.ObjStart()
 	var (
 		first = true
 		_     = first
 	)
-	for k, elem := range s {
+	{
 		if !first {
 			e.Comma()
 		}
-		first = true
-		e.Str(k)
-		e.RawStr(`:`)
+		first = false
 
-		e.Str(elem)
+		e.RawStr("\"common-1\"" + ":")
+		e.Str(s.CommonMinus1)
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"common-2\"" + ":")
+		e.Int(s.CommonMinus2)
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"unique-2\"" + ":")
+		e.Str(s.UniqueMinus2)
 	}
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfMapWithPropertiesInlinedSubMap = [0]string{}
+var jsonFieldsNameOfIssue1431 = [3]string{
+	0: "common-1",
+	1: "common-2",
+	2: "unique-2",
+}
 
-// Decode decodes MapWithPropertiesInlinedSubMap from json.
-func (s MapWithPropertiesInlinedSubMap) Decode(d *jx.Decoder) error {
+// Decode decodes Issue1431 from json.
+func (s *Issue1431) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode MapWithPropertiesInlinedSubMap to nil`)
+		return errors.New(`invalid: unable to decode Issue1431 to nil`)
 	}
+	var requiredBitSet [1]uint8
 
-	m := s
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		default:
-			var elem string
+		case "common-1":
+			requiredBitSet[0] |= 1 << 0
 			v, err := d.Str()
-			elem = string(v)
+			s.CommonMinus1 = string(v)
 			if err != nil {
 				return err
 			}
-			m[string(k)] = elem
+		case "common-2":
+			requiredBitSet[0] |= 1 << 1
+			v, err := d.Int()
+			s.CommonMinus2 = int(v)
+			if err != nil {
+				return err
+			}
+		case "unique-2":
+			requiredBitSet[0] |= 1 << 2
+			v, err := d.Str()
+			s.UniqueMinus2 = string(v)
+			if err != nil {
+				return err
+			}
+		default:
+			return d.Skip()
 		}
 		return nil
 	}); err != nil {
 		return err
 	}
+	var failures []validate.FieldError
+	for i, mask := range [1]uint8{
+		0b00000111,
+	} {
+		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
+			// Mask only required fields and check equality to mask using XOR.
+			//
+			// If XOR result is not zero, result is not equal to expected, so some fields are missed.
+			// Bits of fields which would be set are actually bits of missed fields.
+			missed := bits.OnesCount8(result)
+			for bitN := 0; bitN < missed; bitN++ {
+				bitIdx := bits.TrailingZeros8(result)
+				fieldIdx := i*8 + bitIdx
+				var name string
+				if fieldIdx < len(jsonFieldsNameOfIssue1431) {
+					name = jsonFieldsNameOfIssue1431[fieldIdx]
+				} else {
+					name = strconv.Itoa(fieldIdx)
+				}
+				failures = append(failures, validate.FieldError{
+					Name:  name,
+					Error: validate.ErrFieldRequired,
+				})
+				// Reset bit.
+				result &^= 1 << bitIdx
+			}
+		}
+	}
+	if len(failures) > 0 {
+		return &validate.Error{Fields: failures}
+	}
 
 	return nil
 }
 
-// Encode encodes NullableEnumsBoth as json.
-func (o NilNullableEnumsBoth) Encode(e *jx.Writer) {
-	if o.Null {
-		e.Null()
-		return
-	}
-	e.Str(string(o.Value))
-}
-
-// Decode decodes NullableEnumsBoth from json.
+// Encode implements json.Marshaler.
+func (s Issue1432) Encode(e *jx.Writer) {
+	e.ObjStart()
+	var (
+		first = true
+		_     = first
+	)
+	{
+		if !first {
+			e.Comma()
+		}
+		first = false
+
+		e.RawStr("\"common-1\"" + ":")
+		e.Str(s.CommonMinus1)
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"common-2\"" + ":")
+		e.Int(s.CommonMinus2)
+	}
+	{
+		if s.CommonMinus3.Set {
+			e.Comma()
+		}
+		if s.CommonMinus3.Set {
+			e.RawStr("\"common-3\"" + ":")
+			s.CommonMinus3.Encode(e)
+		}
+	}
+	{
+		e.Comma()
+
+		e.RawStr("\"unique-3\"" + ":")
+		e.Str(s.UniqueMinus3)
+	}
+	e.ObjEnd()
+}
+
+var jsonFieldsNameOfIssue1432 = [4]string{
+	0: "common-1",
+	1: "common-2",
+	2: "common-3",
+	3: "unique-3",
+}
+
+// Decode decodes Issue1432 from json.
+func (s *Issue1432) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode Issue1432 to nil`)
+	}
+	var requiredBitSet [1]uint8
+
+	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
+		switch string(k) {
+		case "common-1":
+			requiredBitSet[0] |= 1 << 0
+			v, err := d.Str()
+			s.CommonMinus1 = string(v)
+			if err != nil {
+				return err
+			}
+		case "common-2":
+			requiredBitSet[0] |= 1 << 1
+			v, err := d.Int()
+			s.CommonMinus2 = int(v)
+			if err != nil {
+				return err
+			}
+		case "common-3":
+			s.CommonMinus3.Reset()
+			if err := s.CommonMinus3.Decode(d); err != nil {
+				return err
+			}
+		case "unique-3":
+			requiredBitSet[0] |= 1 << 3
+			v, err := d.Str()
+			s.UniqueMinus3 = string(v)
+			if err != nil {
+				return err
+			}
+		default:
+			return d.Skip()
+		}
+		return nil
+	}); err != nil {
+		return err
+	}
+	var failures []validate.FieldError
+	for i, mask := range [1]uint8{
+		0b00001011,
+	} {
+		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
+			// Mask only required fields and check equality to mask using XOR.
+			//
+			// If XOR result is not zero, result is not equal to expected, so some fields are missed.
+			// Bits of fields which would be set are actually bits of missed fields.
+			missed := bits.OnesCount8(result)
+			for bitN := 0; bitN < missed; bitN++ {
+				bitIdx := bits.TrailingZeros8(result)
+				fieldIdx := i*8 + bitIdx
+				var name string
+				if fieldIdx < len(jsonFieldsNameOfIssue1432) {
+					name = jsonFieldsNameOfIssue1432[fieldIdx]
+				} else {
+					name = strconv.Itoa(fieldIdx)
+				}
+				failures = append(failures, validate.FieldError{
+					Name:  name,
+					Error: validate.ErrFieldRequired,
+				})
+				// Reset bit.
+				result &^= 1 << bitIdx
+			}
+		}
+	}
+	if len(failures) > 0 {
+		return &validate.Error{Fields: failures}
+	}
+
+	return nil
+}
+
+// Encode implements json.Marshaler.
+func (s Issue1433) Encode(e *jx.Writer) {
+	e.ObjStart()
+	var (
+		first = true
+		_     = first
+	)
+	{
+		if s.CommonMinus3.Set {
+			if !first {
+				e.Comma()
+			}
+			first = false
+		}
+		if s.CommonMinus3.Set {
+			e.RawStr("\"common-3\"" + ":")
+			s.CommonMinus3.Encode(e)
+		}
+	}
+	{
+		if !first {
+			e.Comma()
+		}
+		first = false
+
+		e.RawStr("\"unique-4\"" + ":")
+		e.Str(s.UniqueMinus4)
+	}
+	e.ObjEnd()
+}
+
+var jsonFieldsNameOfIssue1433 = [2]string{
+	0: "common-3",
+	1: "unique-4",
+}
+
+// Decode decodes Issue1433 from json.
+func (s *Issue1433) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode Issue1433 to nil`)
+	}
+	var requiredBitSet [1]uint8
+
+	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
+		switch string(k) {
+		case "common-3":
+			s.CommonMinus3.Reset()
+			if err := s.CommonMinus3.Decode(d); err != nil {
+				return err
+			}
+		case "unique-4":
+			requiredBitSet[0] |= 1 << 1
+			v, err := d.Str()
+			s.UniqueMinus4 = string(v)
+			if err != nil {
+				return err
+			}
+		default:
+			return d.Skip()
+		}
+		return nil
+	}); err != nil {
+		return err
+	}
+	var failures []validate.FieldError
+	for i, mask := range [1]uint8{
+		0b00000010,
+	} {
+		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
+			// Mask only required fields and check equality to mask using XOR.
+			//
+			// If XOR result is not zero, result is not equal to expected, so some fields are missed.
+			// Bits of fields which would be set are actually bits of missed fields.
+			missed := bits.OnesCount8(result)
+			for bitN := 0; bitN < missed; bitN++ {
+				bitIdx := bits.TrailingZeros8(result)
+				fieldIdx := i*8 + bitIdx
+				var name string
+				if fieldIdx < len(jsonFieldsNameOfIssue1433) {
+					name = jsonFieldsNameOfIssue1433[fieldIdx]
+				} else {
+					name = strconv.Itoa(fieldIdx)
+				}
+				failures = append(failures, validate.FieldError{
+					Name:  name,
+					Error: validate.ErrFieldRequired,
+				})
+				// Reset bit.
+				result &^= 1 << bitIdx
+			}
+		}
+	}
+	if len(failures) > 0 {
+		return &validate.Error{Fields: failures}
+	}
+
+	return nil
+}
+
+// Encode implements json.Marshaler.
+func (s MapWithProperties) Encode(e *jx.Writer) {
+	e.ObjStart()
+	var (
+		first = true
+		_     = first
+	)
+	{
+		{
+			if !first {
+				e.Comma()
+			}
+			first = false
+
+			e.RawStr("\"required\"" + ":")
+			e.Int(s.Required)
+		}
+		{
+			if s.Optional.Set {
+				e.Comma()
+			}
+			if s.Optional.Set {
+				e.RawStr("\"optional\"" + ":")
+				s.Optional.Encode(e)
+			}
+		}
+		{
+			if s.SubMap.Set {
+				e.Comma()
+			}
+			if s.SubMap.Set {
+				e.RawStr("\"sub_map\"" + ":")
+				s.SubMap.Encode(e)
+			}
+		}
+		{
+			if s.InlinedSubMap.Set {
+				e.Comma()
+			}
+			if s.InlinedSubMap.Set {
+				e.RawStr("\"inlined_sub_map\"" + ":")
+				s.InlinedSubMap.Encode(e)
+			}
+		}
+	}
+	for k, elem := range s.AdditionalProps {
+		if !first {
+			e.Comma()
+		}
+		first = true
+		e.Str(k)
+		e.RawStr(`:`)
+
+		e.Str(elem)
+	}
+	e.ObjEnd()
+}
+
+var jsonFieldsNameOfMapWithProperties = [4]string{
+	0: "required",
+	1: "optional",
+	2: "sub_map",
+	3: "inlined_sub_map",
+}
+
+// Decode decodes MapWithProperties from json.
+func (s *MapWithProperties) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode MapWithProperties to nil`)
+	}
+	var requiredBitSet [1]uint8
+
+	m := s.AdditionalProps
+	if m == nil {
+		m = map[string]string{}
+		s.AdditionalProps = m
+	}
+	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
+		switch string(k) {
+		case "required":
+			requiredBitSet[0] |= 1 << 0
+			v, err := d.Int()
+			s.Required = int(v)
+			if err != nil {
+				return err
+			}
+		case "optional":
+			s.Optional.Reset()
+			if err := s.Optional.Decode(d); err != nil {
+				return err
+			}
+		case "sub_map":
+			s.SubMap.Reset()
+			if err := s.SubMap.Decode(d); err != nil {
+				return err
+			}
+		case "inlined_sub_map":
+			s.InlinedSubMap.Reset()
+			if err := s.InlinedSubMap.Decode(d); err != nil {
+				return err
+			}
+		default:
+			var elem string
+			v, err := d.Str()
+			elem = string(v)
+			if err != nil {
+				return err
+			}
+			m[string(k)] = elem
+		}
+		return nil
+	}); err != nil {
+		return err
+	}
+	var failures []validate.FieldError
+	for i, mask := range [1]uint8{
+		0b00000001,
+	} {
+		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
+			// Mask only required fields and check equality to mask using XOR.
+			//
+			// If XOR result is not zero, result is not equal to expected, so some fields are missed.
+			// Bits of fields which would be set are actually bits of missed fields.
+			missed := bits.OnesCount8(result)
+			for bitN := 0; bitN < missed; bitN++ {
+				bitIdx := bits.TrailingZeros8(result)
+				fieldIdx := i*8 + bitIdx
+				var name string
+				if fieldIdx < len(jsonFieldsNameOfMapWithProperties) {
+					name = jsonFieldsNameOfMapWithProperties[fieldIdx]
+				} else {
+					name = strconv.Itoa(fieldIdx)
+				}
+				failures = append(failures, validate.FieldError{
+					Name:  name,
+					Error: validate.ErrFieldRequired,
+				})
+				// Reset bit.
+				result &^= 1 << bitIdx
+			}
+		}
+	}
+	if len(failures) > 0 {
+		return &validate.Error{Fields: failures}
+	}
+
+	return nil
+}
+
+// Encode implements json.Marshaler.
+func (s MapWithPropertiesInlinedSubMap) Encode(e *jx.Writer) {
+	e.ObjStart()
+	var (
+		first = true
+		_     = first
+	)
+	for k, elem := range s {
+		if !first {
+			e.Comma()
+		}
+		first = true
+		e.Str(k)
+		e.RawStr(`:`)
+
+		e.Str(elem)
+	}
+	e.ObjEnd()
+}
+
+var jsonFieldsNameOfMapWithPropertiesInlinedSubMap = [0]string{}
+
+// Decode decodes MapWithPropertiesInlinedSubMap from json.
+func (s MapWithPropertiesInlinedSubMap) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode MapWithPropertiesInlinedSubMap to nil`)
+	}
+
+	m := s
+	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
+		switch string(k) {
+		default:
+			var elem string
+			v, err := d.Str()
+			elem = string(v)
+			if err != nil {
+				return err
+			}
+			m[string(k)] = elem
+		}
+		return nil
+	}); err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// Encode encodes NullableEnumsBoth as json.
+func (o NilNullableEnumsBoth) Encode(e *jx.Writer) {
+	if o.Null {
+		e.Null()
+		return
+	}
+	e.Str(string(o.Value))
+}
+
+// Decode decodes NullableEnumsBoth from json.
 func (o *NilNullableEnumsBoth) Decode(d *jx.Decoder) error {
 	if o == nil {
 		return errors.New(`invalid: unable to decode NilNullableEnumsBoth to nil`)
@@ -1234,298 +1751,34 @@ func (s NullableEnums) Encode(e *jx.Writer) {
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfNullableEnums = [3]string{
-	0: "only_nullable",
-	1: "only_null_value",
-	2: "both",
-}
-
-// Decode decodes NullableEnums from json.
-func (s *NullableEnums) Decode(d *jx.Decoder) error {
-	if s == nil {
-		return errors.New(`invalid: unable to decode NullableEnums to nil`)
-	}
-	var requiredBitSet [1]uint8
-
-	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
-		switch string(k) {
-		case "only_nullable":
-			requiredBitSet[0] |= 1 << 0
-			if err := s.OnlyNullable.Decode(d); err != nil {
-				return err
-			}
-		case "only_null_value":
-			requiredBitSet[0] |= 1 << 1
-			if err := s.OnlyNullValue.Decode(d); err != nil {
-				return err
-			}
-		case "both":
-			requiredBitSet[0] |= 1 << 2
-			if err := s.Both.Decode(d); err != nil {
-				return err
-			}
-		default:
-			return d.Skip()
-		}
-		return nil
-	}); err != nil {
-		return err
-	}
-	var failures []validate.FieldError
-	for i, mask := range [1]uint8{
-		0b00000111,
-	} {
-		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
-			// Mask only required fields and check equality to mask using XOR.
-			//
-			// If XOR result is not zero, result is not equal to expected, so some fields are missed.
-			// Bits of fields which would be set are actually bits of missed fields.
-			missed := bits.OnesCount8(result)
-			for bitN := 0; bitN < missed; bitN++ {
-				bitIdx := bits.TrailingZeros8(result)
-				fieldIdx := i*8 + bitIdx
-				var name string
-				if fieldIdx < len(jsonFieldsNameOfNullableEnums) {
-					name = jsonFieldsNameOfNullableEnums[fieldIdx]
-				} else {
-					name = strconv.Itoa(fieldIdx)
-				}
-				failures = append(failures, validate.FieldError{
-					Name:  name,
-					Error: validate.ErrFieldRequired,
-				})
-				// Reset bit.
-				result &^= 1 << bitIdx
-			}
-		}
-	}
-	if len(failures) > 0 {
-		return &validate.Error{Fields: failures}
-	}
-
-	return nil
-}
-
-// Encode encodes NullableEnumsBoth as json.
-func (s NullableEnumsBoth) Encode(e *jx.Writer) {
-	e.Str(string(s))
-}
-
-// Decode decodes NullableEnumsBoth from json.
-func (s *NullableEnumsBoth) Decode(d *jx.Decoder) error {
-	if s == nil {
-		return errors.New(`invalid: unable to decode NullableEnumsBoth to nil`)
-	}
-	v, err := d.StrBytes()
-	if err != nil {
-		return err
-	}
-	// Try to use constant string.
-	switch NullableEnumsBoth(v) {
-	case NullableEnumsBothAsc:
-		*s = NullableEnumsBothAsc
-	case NullableEnumsBothDesc:
-		*s = NullableEnumsBothDesc
-	default:
-		*s = NullableEnumsBoth(v)
-	}
-
-	return nil
-}
-
-// Encode encodes NullableEnumsOnlyNullValue as json.
-func (s NullableEnumsOnlyNullValue) Encode(e *jx.Writer) {
-	e.Str(string(s))
-}
-
-// Decode decodes NullableEnumsOnlyNullValue from json.
-func (s *NullableEnumsOnlyNullValue) Decode(d *jx.Decoder) error {
-	if s == nil {
-		return errors.New(`invalid: unable to decode NullableEnumsOnlyNullValue to nil`)
-	}
-	v, err := d.StrBytes()
-	if err != nil {
-		return err
-	}
-	// Try to use constant string.
-	switch NullableEnumsOnlyNullValue(v) {
-	case NullableEnumsOnlyNullValueAsc:
-		*s = NullableEnumsOnlyNullValueAsc
-	case NullableEnumsOnlyNullValueDesc:
-		*s = NullableEnumsOnlyNullValueDesc
-	default:
-		*s = NullableEnumsOnlyNullValue(v)
-	}
-
-	return nil
-}
-
-// Encode encodes NullableEnumsOnlyNullable as json.
-func (s NullableEnumsOnlyNullable) Encode(e *jx.Writer) {
-	e.Str(string(s))
-}
-
-// Decode decodes NullableEnumsOnlyNullable from json.
-func (s *NullableEnumsOnlyNullable) Decode(d *jx.Decoder) error {
-	if s == nil {
-		return errors.New(`invalid: unable to decode NullableEnumsOnlyNullable to nil`)
-	}
-	v, err := d.StrBytes()
-	if err != nil {
-		return err
-	}
-	// Try to use constant string.
-	switch NullableEnumsOnlyNullable(v) {
-	case NullableEnumsOnlyNullableAsc:
-		*s = NullableEnumsOnlyNullableAsc
-	case NullableEnumsOnlyNullableDesc:
-		*s = NullableEnumsOnlyNullableDesc
-	default:
-		*s = NullableEnumsOnlyNullable(v)
-	}
-
-	return nil
-}
-
-// Encode encodes OneofBugReq as json.
-func (s OneofBugReq) Encode(e *jx.Writer) {
-	switch s.Type {
-	case OneofBugReq0OneofBugReq:
-		s.OneofBugReq0.Encode(e)
-	case OneofBugReq1OneofBugReq:
-		s.OneofBugReq1.Encode(e)
-	case OneofBugReq2OneofBugReq:
-		s.OneofBugReq2.Encode(e)
-	case OneofBugReq3OneofBugReq:
-		s.OneofBugReq3.Encode(e)
-	}
-}
-
-// Decode decodes OneofBugReq from json.
-func (s *OneofBugReq) Decode(d *jx.Decoder) error {
-	if s == nil {
-		return errors.New(`invalid: unable to decode OneofBugReq to nil`)
-	}
-	// Sum type fields.
-	if d.Next() != jx.Object {
-		return errors.Errorf("unexpected json type %q", d.Next())
-	}
-	var found bool
-	if err := d.Capture(func(d *jx.Decoder) error {
-		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
-			if found {
-				return d.Skip()
-			}
-			switch string(key) {
-			case "unique-1":
-				found = true
-				s.Type = OneofBugReq0OneofBugReq
-			case "unique-2":
-				found = true
-				s.Type = OneofBugReq1OneofBugReq
-			case "unique-3":
-				found = true
-				s.Type = OneofBugReq2OneofBugReq
-			case "unique-4":
-				found = true
-				s.Type = OneofBugReq3OneofBugReq
-			}
-			return d.Skip()
-		})
-	}); err != nil {
-		return errors.Wrap(err, "capture")
-	}
-	if !found {
-		return errors.New("unable to detect sum type variant")
-	}
-	switch s.Type {
-	case OneofBugReq0OneofBugReq:
-		if err := s.OneofBugReq0.Decode(d); err != nil {
-			return err
-		}
-	case OneofBugReq1OneofBugReq:
-		if err := s.OneofBugReq1.Decode(d); err != nil {
-			return err
-		}
-	case OneofBugReq2OneofBugReq:
-		if err := s.OneofBugReq2.Decode(d); err != nil {
-			return err
-		}
-	case OneofBugReq3OneofBugReq:
-		if err := s.OneofBugReq3.Decode(d); err != nil {
-			return err
-		}
-	default:
-		return errors.Errorf("inferred invalid type: %s", s.Type)
-	}
-	return nil
-}
-
-// Encode implements json.Marshaler.
-func (s OneofBugReq0) Encode(e *jx.Writer) {
-	e.ObjStart()
-	var (
-		first = true
-		_     = first
-	)
-	{
-		if !first {
-			e.Comma()
-		}
-		first = false
-
-		e.RawStr("\"common-1\"" + ":")
-		e.Str(s.CommonMinus1)
-	}
-	{
-		e.Comma()
-
-		e.RawStr("\"common-2\"" + ":")
-		e.Int(s.CommonMinus2)
-	}
-	{
-		e.Comma()
-
-		e.RawStr("\"unique-1\"" + ":")
-		e.Str(s.UniqueMinus1)
-	}
-	e.ObjEnd()
-}
-
-var jsonFieldsNameOfOneofBugReq0 = [3]string{
-	0: "common-1",
-	1: "common-2",
-	2: "unique-1",
+var jsonFieldsNameOfNullableEnums = [3]string{
+	0: "only_nullable",
+	1: "only_null_value",
+	2: "both",
 }
 
-// Decode decodes OneofBugReq0 from json.
-func (s *OneofBugReq0) Decode(d *jx.Decoder) error {
+// Decode decodes NullableEnums from json.
+func (s *NullableEnums) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode OneofBugReq0 to nil`)
+		return errors.New(`invalid: unable to decode NullableEnums to nil`)
 	}
 	var requiredBitSet [1]uint8
 
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		case "common-1":
+		case "only_nullable":
 			requiredBitSet[0] |= 1 << 0
-			v, err := d.Str()
-			s.CommonMinus1 = string(v)
-			if err != nil {
+			if err := s.OnlyNullable.Decode(d); err != nil {
 				return err
 			}
-		case "common-2":
+		case "only_null_value":
 			requiredBitSet[0] |= 1 << 1
-			v, err := d.Int()
-			s.CommonMinus2 = int(v)
-			if err != nil {
+			if err := s.OnlyNullValue.Decode(d); err != nil {
 				return err
 			}
-		case "unique-1":
+		case "both":
 			requiredBitSet[0] |= 1 << 2
-			v, err := d.Str()
-			s.UniqueMinus1 = string(v)
-			if err != nil {
+			if err := s.Both.Decode(d); err != nil {
 				return err
 			}
 		default:
@@ -1549,8 +1802,8 @@ func (s *OneofBugReq0) Decode(d *jx.Decoder) error {
 				bitIdx := bits.TrailingZeros8(result)
 				fieldIdx := i*8 + bitIdx
 				var name string
-				if fieldIdx < len(jsonFieldsNameOfOneofBugReq0) {
-					name = jsonFieldsNameOfOneofBugReq0[fieldIdx]
+				if fieldIdx < len(jsonFieldsNameOfNullableEnums) {
+					name = jsonFieldsNameOfNullableEnums[fieldIdx]
 				} else {
 					name = strconv.Itoa(fieldIdx)
 				}
@@ -1570,8 +1823,89 @@ func (s *OneofBugReq0) Decode(d *jx.Decoder) error {
 	return nil
 }
 
+// Encode encodes NullableEnumsBoth as json.
+func (s NullableEnumsBoth) Encode(e *jx.Writer) {
+	e.Str(string(s))
+}
+
+// Decode decodes NullableEnumsBoth from json.
+func (s *NullableEnumsBoth) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode NullableEnumsBoth to nil`)
+	}
+	v, err := d.StrBytes()
+	if err != nil {
+		return err
+	}
+	// Try to use constant string.
+	switch NullableEnumsBoth(v) {
+	case NullableEnumsBothAsc:
+		*s = NullableEnumsBothAsc
+	case NullableEnumsBothDesc:
+		*s = NullableEnumsBothDesc
+	default:
+		*s = NullableEnumsBoth(v)
+	}
+
+	return nil
+}
+
+// Encode encodes NullableEnumsOnlyNullValue as json.
+func (s NullableEnumsOnlyNullValue) Encode(e *jx.Writer) {
+	e.Str(string(s))
+}
+
+// Decode decodes NullableEnumsOnlyNullValue from json.
+func (s *NullableEnumsOnlyNullValue) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode NullableEnumsOnlyNullValue to nil`)
+	}
+	v, err := d.StrBytes()
+	if err != nil {
+		return err
+	}
+	// Try to use constant string.
+	switch NullableEnumsOnlyNullValue(v) {
+	case NullableEnumsOnlyNullValueAsc:
+		*s = NullableEnumsOnlyNullValueAsc
+	case NullableEnumsOnlyNullValueDesc:
+		*s = NullableEnumsOnlyNullValueDesc
+	default:
+		*s = NullableEnumsOnlyNullValue(v)
+	}
+
+	return nil
+}
+
+// Encode encodes NullableEnumsOnlyNullable as json.
+func (s NullableEnumsOnlyNullable) Encode(e *jx.Writer) {
+	e.Str(string(s))
+}
+
+// Decode decodes NullableEnumsOnlyNullable from json.
+func (s *NullableEnumsOnlyNullable) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode NullableEnumsOnlyNullable to nil`)
+	}
+	v, err := d.StrBytes()
+	if err != nil {
+		return err
+	}
+	// Try to use constant string.
+	switch NullableEnumsOnlyNullable(v) {
+	case NullableEnumsOnlyNullableAsc:
+		*s = NullableEnumsOnlyNullableAsc
+	case NullableEnumsOnlyNullableDesc:
+		*s = NullableEnumsOnlyNullableDesc
+	default:
+		*s = NullableEnumsOnlyNullable(v)
+	}
+
+	return nil
+}
+
 // Encode implements json.Marshaler.
-func (s OneofBugReq1) Encode(e *jx.Writer) {
+func (s OneOfBugs) Encode(e *jx.Writer) {
 	e.ObjStart()
 	var (
 		first = true
@@ -1583,58 +1917,40 @@ func (s OneofBugReq1) Encode(e *jx.Writer) {
 		}
 		first = false
 
-		e.RawStr("\"common-1\"" + ":")
-		e.Str(s.CommonMinus1)
-	}
-	{
-		e.Comma()
-
-		e.RawStr("\"common-2\"" + ":")
-		e.Int(s.CommonMinus2)
+		e.RawStr("\"issue143\"" + ":")
+		s.Issue143.Encode(e)
 	}
 	{
 		e.Comma()
 
-		e.RawStr("\"unique-2\"" + ":")
-		e.Str(s.UniqueMinus2)
+		e.RawStr("\"additional-fields\"" + ":")
+		s.AdditionalMinusFields.Encode(e)
 	}
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfOneofBugReq1 = [3]string{
-	0: "common-1",
-	1: "common-2",
-	2: "unique-2",
+var jsonFieldsNameOfOneOfBugs = [2]string{
+	0: "issue143",
+	1: "additional-fields",
 }
 
-// Decode decodes OneofBugReq1 from json.
-func (s *OneofBugReq1) Decode(d *jx.Decoder) error {
+// Decode decodes OneOfBugs from json.
+func (s *OneOfBugs) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode OneofBugReq1 to nil`)
+		return errors.New(`invalid: unable to decode OneOfBugs to nil`)
 	}
 	var requiredBitSet [1]uint8
 
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		case "common-1":
+		case "issue143":
 			requiredBitSet[0] |= 1 << 0
-			v, err := d.Str()
-			s.CommonMinus1 = string(v)
-			if err != nil {
+			if err := s.Issue143.Decode(d); err != nil {
 				return err
 			}
-		case "common-2":
+		case "additional-fields":
 			requiredBitSet[0] |= 1 << 1
-			v, err := d.Int()
-			s.CommonMinus2 = int(v)
-			if err != nil {
-				return err
-			}
-		case "unique-2":
-			requiredBitSet[0] |= 1 << 2
-			v, err := d.Str()
-			s.UniqueMinus2 = string(v)
-			if err != nil {
+			if err := s.AdditionalMinusFields.Decode(d); err != nil {
 				return err
 			}
 		default:
@@ -1646,7 +1962,7 @@ func (s *OneofBugReq1) Decode(d *jx.Decoder) error {
 	}
 	var failures []validate.FieldError
 	for i, mask := range [1]uint8{
-		0b00000111,
+		0b00000011,
 	} {
 		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
 			// Mask only required fields and check equality to mask using XOR.
@@ -1658,8 +1974,8 @@ func (s *OneofBugReq1) Decode(d *jx.Decoder) error {
 				bitIdx := bits.TrailingZeros8(result)
 				fieldIdx := i*8 + bitIdx
 				var name string
-				if fieldIdx < len(jsonFieldsNameOfOneofBugReq1) {
-					name = jsonFieldsNameOfOneofBugReq1[fieldIdx]
+				if fieldIdx < len(jsonFieldsNameOfOneOfBugs) {
+					name = jsonFieldsNameOfOneOfBugs[fieldIdx]
 				} else {
 					name = strconv.Itoa(fieldIdx)
 				}
@@ -1679,8 +1995,62 @@ func (s *OneofBugReq1) Decode(d *jx.Decoder) error {
 	return nil
 }
 
+// Encode encodes OneVariantHasNoUniqueFields as json.
+func (s OneVariantHasNoUniqueFields) Encode(e *jx.Writer) {
+	switch s.Type {
+	case OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields:
+		s.OneVariantHasNoUniqueFields0.Encode(e)
+	case OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields:
+		s.OneVariantHasNoUniqueFields1.Encode(e)
+	}
+}
+
+// Decode decodes OneVariantHasNoUniqueFields from json.
+func (s *OneVariantHasNoUniqueFields) Decode(d *jx.Decoder) error {
+	if s == nil {
+		return errors.New(`invalid: unable to decode OneVariantHasNoUniqueFields to nil`)
+	}
+	// Sum type fields.
+	if d.Next() != jx.Object {
+		return errors.Errorf("unexpected json type %q", d.Next())
+	}
+
+	var found bool
+	if err := d.Capture(func(d *jx.Decoder) error {
+		return d.ObjBytes(func(d *jx.Decoder, key []byte) error {
+			if found {
+				return d.Skip()
+			}
+			switch string(key) {
+			case "d":
+				found = true
+				s.Type = OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields
+			}
+			return d.Skip()
+		})
+	}); err != nil {
+		return errors.Wrap(err, "capture")
+	}
+	if !found {
+		s.Type = OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields
+	}
+	switch s.Type {
+	case OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields:
+		if err := s.OneVariantHasNoUniqueFields0.Decode(d); err != nil {
+			return err
+		}
+	case OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields:
+		if err := s.OneVariantHasNoUniqueFields1.Decode(d); err != nil {
+			return err
+		}
+	default:
+		return errors.Errorf("inferred invalid type: %s", s.Type)
+	}
+	return nil
+}
+
 // Encode implements json.Marshaler.
-func (s OneofBugReq2) Encode(e *jx.Writer) {
+func (s OneVariantHasNoUniqueFields0) Encode(e *jx.Writer) {
 	e.ObjStart()
 	var (
 		first = true
@@ -1692,72 +2062,58 @@ func (s OneofBugReq2) Encode(e *jx.Writer) {
 		}
 		first = false
 
-		e.RawStr("\"common-1\"" + ":")
-		e.Str(s.CommonMinus1)
-	}
-	{
-		e.Comma()
-
-		e.RawStr("\"common-2\"" + ":")
-		e.Int(s.CommonMinus2)
+		e.RawStr("\"a\"" + ":")
+		e.Str(s.A)
 	}
 	{
-		if s.CommonMinus3.Set {
+		if s.B.Set {
 			e.Comma()
 		}
-		if s.CommonMinus3.Set {
-			e.RawStr("\"common-3\"" + ":")
-			s.CommonMinus3.Encode(e)
+		if s.B.Set {
+			e.RawStr("\"b\"" + ":")
+			s.B.Encode(e)
 		}
 	}
 	{
 		e.Comma()
 
-		e.RawStr("\"unique-3\"" + ":")
-		e.Str(s.UniqueMinus3)
+		e.RawStr("\"c\"" + ":")
+		e.Str(s.C)
 	}
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfOneofBugReq2 = [4]string{
-	0: "common-1",
-	1: "common-2",
-	2: "common-3",
-	3: "unique-3",
+var jsonFieldsNameOfOneVariantHasNoUniqueFields0 = [3]string{
+	0: "a",
+	1: "b",
+	2: "c",
 }
 
-// Decode decodes OneofBugReq2 from json.
-func (s *OneofBugReq2) Decode(d *jx.Decoder) error {
+// Decode decodes OneVariantHasNoUniqueFields0 from json.
+func (s *OneVariantHasNoUniqueFields0) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode OneofBugReq2 to nil`)
+		return errors.New(`invalid: unable to decode OneVariantHasNoUniqueFields0 to nil`)
 	}
 	var requiredBitSet [1]uint8
 
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		case "common-1":
+		case "a":
 			requiredBitSet[0] |= 1 << 0
 			v, err := d.Str()
-			s.CommonMinus1 = string(v)
-			if err != nil {
-				return err
-			}
-		case "common-2":
-			requiredBitSet[0] |= 1 << 1
-			v, err := d.Int()
-			s.CommonMinus2 = int(v)
+			s.A = string(v)
 			if err != nil {
 				return err
 			}
-		case "common-3":
-			s.CommonMinus3.Reset()
-			if err := s.CommonMinus3.Decode(d); err != nil {
+		case "b":
+			s.B.Reset()
+			if err := s.B.Decode(d); err != nil {
 				return err
 			}
-		case "unique-3":
-			requiredBitSet[0] |= 1 << 3
+		case "c":
+			requiredBitSet[0] |= 1 << 2
 			v, err := d.Str()
-			s.UniqueMinus3 = string(v)
+			s.C = string(v)
 			if err != nil {
 				return err
 			}
@@ -1770,7 +2126,7 @@ func (s *OneofBugReq2) Decode(d *jx.Decoder) error {
 	}
 	var failures []validate.FieldError
 	for i, mask := range [1]uint8{
-		0b00001011,
+		0b00000101,
 	} {
 		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
 			// Mask only required fields and check equality to mask using XOR.
@@ -1782,8 +2138,8 @@ func (s *OneofBugReq2) Decode(d *jx.Decoder) error {
 				bitIdx := bits.TrailingZeros8(result)
 				fieldIdx := i*8 + bitIdx
 				var name string
-				if fieldIdx < len(jsonFieldsNameOfOneofBugReq2) {
-					name = jsonFieldsNameOfOneofBugReq2[fieldIdx]
+				if fieldIdx < len(jsonFieldsNameOfOneVariantHasNoUniqueFields0) {
+					name = jsonFieldsNameOfOneVariantHasNoUniqueFields0[fieldIdx]
 				} else {
 					name = strconv.Itoa(fieldIdx)
 				}
@@ -1804,62 +2160,88 @@ func (s *OneofBugReq2) Decode(d *jx.Decoder) error {
 }
 
 // Encode implements json.Marshaler.
-func (s OneofBugReq3) Encode(e *jx.Writer) {
+func (s OneVariantHasNoUniqueFields1) Encode(e *jx.Writer) {
 	e.ObjStart()
 	var (
 		first = true
 		_     = first
 	)
 	{
-		if s.CommonMinus3.Set {
-			if !first {
-				e.Comma()
-			}
-			first = false
-		}
-		if s.CommonMinus3.Set {
-			e.RawStr("\"common-3\"" + ":")
-			s.CommonMinus3.Encode(e)
+		if !first {
+			e.Comma()
 		}
+		first = false
+
+		e.RawStr("\"a\"" + ":")
+		e.Str(s.A)
 	}
 	{
-		if !first {
+		if s.B.Set {
 			e.Comma()
 		}
-		first = false
+		if s.B.Set {
+			e.RawStr("\"b\"" + ":")
+			s.B.Encode(e)
+		}
+	}
+	{
+		e.Comma()
 
-		e.RawStr("\"unique-4\"" + ":")
-		e.Str(s.UniqueMinus4)
+		e.RawStr("\"c\"" + ":")
+		e.Str(s.C)
+	}
+	{
+		if s.D.Set {
+			e.Comma()
+		}
+		if s.D.Set {
+			e.RawStr("\"d\"" + ":")
+			s.D.Encode(e)
+		}
 	}
 	e.ObjEnd()
 }
 
-var jsonFieldsNameOfOneofBugReq3 = [2]string{
-	0: "common-3",
-	1: "unique-4",
+var jsonFieldsNameOfOneVariantHasNoUniqueFields1 = [4]string{
+	0: "a",
+	1: "b",
+	2: "c",
+	3: "d",
 }
 
-// Decode decodes OneofBugReq3 from json.
-func (s *OneofBugReq3) Decode(d *jx.Decoder) error {
+// Decode decodes OneVariantHasNoUniqueFields1 from json.
+func (s *OneVariantHasNoUniqueFields1) Decode(d *jx.Decoder) error {
 	if s == nil {
-		return errors.New(`invalid: unable to decode OneofBugReq3 to nil`)
+		return errors.New(`invalid: unable to decode OneVariantHasNoUniqueFields1 to nil`)
 	}
 	var requiredBitSet [1]uint8
 
 	if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
 		switch string(k) {
-		case "common-3":
-			s.CommonMinus3.Reset()
-			if err := s.CommonMinus3.Decode(d); err != nil {
+		case "a":
+			requiredBitSet[0] |= 1 << 0
+			v, err := d.Str()
+			s.A = string(v)
+			if err != nil {
 				return err
 			}
-		case "unique-4":
-			requiredBitSet[0] |= 1 << 1
+		case "b":
+			s.B.Reset()
+			if err := s.B.Decode(d); err != nil {
+				return err
+			}
+		case "c":
+			requiredBitSet[0] |= 1 << 2
 			v, err := d.Str()
-			s.UniqueMinus4 = string(v)
+			s.C = string(v)
 			if err != nil {
 				return err
 			}
+		case "d":
+			s.D.Reset()
+			if err := s.D.Decode(d); err != nil {
+				return err
+			}
 		default:
 			return d.Skip()
 		}
@@ -1869,7 +2251,7 @@ func (s *OneofBugReq3) Decode(d *jx.Decoder) error {
 	}
 	var failures []validate.FieldError
 	for i, mask := range [1]uint8{
-		0b00000010,
+		0b00000101,
 	} {
 		if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
 			// Mask only required fields and check equality to mask using XOR.
@@ -1881,8 +2263,8 @@ func (s *OneofBugReq3) Decode(d *jx.Decoder) error {
 				bitIdx := bits.TrailingZeros8(result)
 				fieldIdx := i*8 + bitIdx
 				var name string
-				if fieldIdx < len(jsonFieldsNameOfOneofBugReq3) {
-					name = jsonFieldsNameOfOneofBugReq3[fieldIdx]
+				if fieldIdx < len(jsonFieldsNameOfOneVariantHasNoUniqueFields1) {
+					name = jsonFieldsNameOfOneVariantHasNoUniqueFields1[fieldIdx]
 				} else {
 					name = strconv.Itoa(fieldIdx)
 				}
diff --git a/internal/sample_api/oas_req_dec_gen.go b/internal/sample_api/oas_req_dec_gen.go
index 93c8f010..9b18906d 100644
--- a/internal/sample_api/oas_req_dec_gen.go
+++ b/internal/sample_api/oas_req_dec_gen.go
@@ -114,10 +114,10 @@ func decodeFoobarPostRequest(r *http.Request, span trace.Span) (req OptPet, err
 	}
 }
 
-func decodeOneofBugRequest(r *http.Request, span trace.Span) (req OneofBugReq, err error) {
+func decodeOneofBugRequest(r *http.Request, span trace.Span) (req OneOfBugs, err error) {
 	switch r.Header.Get("Content-Type") {
 	case "application/json":
-		var request OneofBugReq
+		var request OneOfBugs
 		buf := getBuf()
 		defer putBuf(buf)
 		written, err := io.Copy(buf, r.Body)
diff --git a/internal/sample_api/oas_req_enc_gen.go b/internal/sample_api/oas_req_enc_gen.go
index f713fbff..9d633ba4 100644
--- a/internal/sample_api/oas_req_enc_gen.go
+++ b/internal/sample_api/oas_req_enc_gen.go
@@ -73,7 +73,7 @@ func encodeFoobarPostRequestJSON(req OptPet, span trace.Span) (data *jx.Writer,
 	return e, nil
 }
 
-func encodeOneofBugRequestJSON(req OneofBugReq, span trace.Span) (data *jx.Writer, err error) {
+func encodeOneofBugRequestJSON(req OneOfBugs, span trace.Span) (data *jx.Writer, err error) {
 	e := jx.GetWriter()
 
 	req.Encode(e)
diff --git a/internal/sample_api/oas_schemas_gen.go b/internal/sample_api/oas_schemas_gen.go
index 78cd9203..2db14a91 100644
--- a/internal/sample_api/oas_schemas_gen.go
+++ b/internal/sample_api/oas_schemas_gen.go
@@ -259,6 +259,147 @@ func NewIntID(v int) ID {
 	return s
 }
 
+// Ref: #/components/schemas/Issue143
+// Issue143 represents sum type.
+type Issue143 struct {
+	Type      Issue143Type // switch on this field
+	Issue1430 Issue1430
+	Issue1431 Issue1431
+	Issue1432 Issue1432
+	Issue1433 Issue1433
+}
+
+// Issue143Type is oneOf type of Issue143.
+type Issue143Type string
+
+// Possible values for Issue143Type.
+const (
+	Issue1430Issue143 Issue143Type = "Issue1430"
+	Issue1431Issue143 Issue143Type = "Issue1431"
+	Issue1432Issue143 Issue143Type = "Issue1432"
+	Issue1433Issue143 Issue143Type = "Issue1433"
+)
+
+// IsIssue1430 reports whether Issue143 is Issue1430.
+func (s Issue143) IsIssue1430() bool { return s.Type == Issue1430Issue143 }
+
+// IsIssue1431 reports whether Issue143 is Issue1431.
+func (s Issue143) IsIssue1431() bool { return s.Type == Issue1431Issue143 }
+
+// IsIssue1432 reports whether Issue143 is Issue1432.
+func (s Issue143) IsIssue1432() bool { return s.Type == Issue1432Issue143 }
+
+// IsIssue1433 reports whether Issue143 is Issue1433.
+func (s Issue143) IsIssue1433() bool { return s.Type == Issue1433Issue143 }
+
+// SetIssue1430 sets Issue143 to Issue1430.
+func (s *Issue143) SetIssue1430(v Issue1430) {
+	s.Type = Issue1430Issue143
+	s.Issue1430 = v
+}
+
+// GetIssue1430 returns Issue1430 and true boolean if Issue143 is Issue1430.
+func (s Issue143) GetIssue1430() (v Issue1430, ok bool) {
+	if !s.IsIssue1430() {
+		return v, false
+	}
+	return s.Issue1430, true
+}
+
+// NewIssue1430Issue143 returns new Issue143 from Issue1430.
+func NewIssue1430Issue143(v Issue1430) Issue143 {
+	var s Issue143
+	s.SetIssue1430(v)
+	return s
+}
+
+// SetIssue1431 sets Issue143 to Issue1431.
+func (s *Issue143) SetIssue1431(v Issue1431) {
+	s.Type = Issue1431Issue143
+	s.Issue1431 = v
+}
+
+// GetIssue1431 returns Issue1431 and true boolean if Issue143 is Issue1431.
+func (s Issue143) GetIssue1431() (v Issue1431, ok bool) {
+	if !s.IsIssue1431() {
+		return v, false
+	}
+	return s.Issue1431, true
+}
+
+// NewIssue1431Issue143 returns new Issue143 from Issue1431.
+func NewIssue1431Issue143(v Issue1431) Issue143 {
+	var s Issue143
+	s.SetIssue1431(v)
+	return s
+}
+
+// SetIssue1432 sets Issue143 to Issue1432.
+func (s *Issue143) SetIssue1432(v Issue1432) {
+	s.Type = Issue1432Issue143
+	s.Issue1432 = v
+}
+
+// GetIssue1432 returns Issue1432 and true boolean if Issue143 is Issue1432.
+func (s Issue143) GetIssue1432() (v Issue1432, ok bool) {
+	if !s.IsIssue1432() {
+		return v, false
+	}
+	return s.Issue1432, true
+}
+
+// NewIssue1432Issue143 returns new Issue143 from Issue1432.
+func NewIssue1432Issue143(v Issue1432) Issue143 {
+	var s Issue143
+	s.SetIssue1432(v)
+	return s
+}
+
+// SetIssue1433 sets Issue143 to Issue1433.
+func (s *Issue143) SetIssue1433(v Issue1433) {
+	s.Type = Issue1433Issue143
+	s.Issue1433 = v
+}
+
+// GetIssue1433 returns Issue1433 and true boolean if Issue143 is Issue1433.
+func (s Issue143) GetIssue1433() (v Issue1433, ok bool) {
+	if !s.IsIssue1433() {
+		return v, false
+	}
+	return s.Issue1433, true
+}
+
+// NewIssue1433Issue143 returns new Issue143 from Issue1433.
+func NewIssue1433Issue143(v Issue1433) Issue143 {
+	var s Issue143
+	s.SetIssue1433(v)
+	return s
+}
+
+type Issue1430 struct {
+	CommonMinus1 string `json:"common-1"`
+	CommonMinus2 int    `json:"common-2"`
+	UniqueMinus1 string `json:"unique-1"`
+}
+
+type Issue1431 struct {
+	CommonMinus1 string `json:"common-1"`
+	CommonMinus2 int    `json:"common-2"`
+	UniqueMinus2 string `json:"unique-2"`
+}
+
+type Issue1432 struct {
+	CommonMinus1 string `json:"common-1"`
+	CommonMinus2 int    `json:"common-2"`
+	CommonMinus3 OptInt `json:"common-3"`
+	UniqueMinus3 string `json:"unique-3"`
+}
+
+type Issue1433 struct {
+	CommonMinus3 OptInt `json:"common-3"`
+	UniqueMinus4 string `json:"unique-4"`
+}
+
 // Ref: #/components/schemas/MapWithProperties
 type MapWithProperties struct {
 	Required        int                               `json:"required"`
@@ -426,148 +567,96 @@ const (
 	NullableEnumsOnlyNullableDesc NullableEnumsOnlyNullable = "desc"
 )
 
-// OneofBugOK is response for OneofBug operation.
-type OneofBugOK struct{}
+// Ref: #/components/schemas/OneOfBugs
+type OneOfBugs struct {
+	Issue143              Issue143                    `json:"issue143"`
+	AdditionalMinusFields OneVariantHasNoUniqueFields `json:"additional-fields"`
+}
 
-// OneofBugReq represents sum type.
-type OneofBugReq struct {
-	Type         OneofBugReqType // switch on this field
-	OneofBugReq0 OneofBugReq0
-	OneofBugReq1 OneofBugReq1
-	OneofBugReq2 OneofBugReq2
-	OneofBugReq3 OneofBugReq3
+// Ref: #/components/schemas/OneVariantHasNoUniqueFields
+// OneVariantHasNoUniqueFields represents sum type.
+type OneVariantHasNoUniqueFields struct {
+	Type                         OneVariantHasNoUniqueFieldsType // switch on this field
+	OneVariantHasNoUniqueFields0 OneVariantHasNoUniqueFields0
+	OneVariantHasNoUniqueFields1 OneVariantHasNoUniqueFields1
 }
 
-// OneofBugReqType is oneOf type of OneofBugReq.
-type OneofBugReqType string
+// OneVariantHasNoUniqueFieldsType is oneOf type of OneVariantHasNoUniqueFields.
+type OneVariantHasNoUniqueFieldsType string
 
-// Possible values for OneofBugReqType.
+// Possible values for OneVariantHasNoUniqueFieldsType.
 const (
-	OneofBugReq0OneofBugReq OneofBugReqType = "OneofBugReq0"
-	OneofBugReq1OneofBugReq OneofBugReqType = "OneofBugReq1"
-	OneofBugReq2OneofBugReq OneofBugReqType = "OneofBugReq2"
-	OneofBugReq3OneofBugReq OneofBugReqType = "OneofBugReq3"
+	OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields OneVariantHasNoUniqueFieldsType = "OneVariantHasNoUniqueFields0"
+	OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields OneVariantHasNoUniqueFieldsType = "OneVariantHasNoUniqueFields1"
 )
 
-// IsOneofBugReq0 reports whether OneofBugReq is OneofBugReq0.
-func (s OneofBugReq) IsOneofBugReq0() bool { return s.Type == OneofBugReq0OneofBugReq }
-
-// IsOneofBugReq1 reports whether OneofBugReq is OneofBugReq1.
-func (s OneofBugReq) IsOneofBugReq1() bool { return s.Type == OneofBugReq1OneofBugReq }
-
-// IsOneofBugReq2 reports whether OneofBugReq is OneofBugReq2.
-func (s OneofBugReq) IsOneofBugReq2() bool { return s.Type == OneofBugReq2OneofBugReq }
-
-// IsOneofBugReq3 reports whether OneofBugReq is OneofBugReq3.
-func (s OneofBugReq) IsOneofBugReq3() bool { return s.Type == OneofBugReq3OneofBugReq }
-
-// SetOneofBugReq0 sets OneofBugReq to OneofBugReq0.
-func (s *OneofBugReq) SetOneofBugReq0(v OneofBugReq0) {
-	s.Type = OneofBugReq0OneofBugReq
-	s.OneofBugReq0 = v
-}
-
-// GetOneofBugReq0 returns OneofBugReq0 and true boolean if OneofBugReq is OneofBugReq0.
-func (s OneofBugReq) GetOneofBugReq0() (v OneofBugReq0, ok bool) {
-	if !s.IsOneofBugReq0() {
-		return v, false
-	}
-	return s.OneofBugReq0, true
-}
-
-// NewOneofBugReq0OneofBugReq returns new OneofBugReq from OneofBugReq0.
-func NewOneofBugReq0OneofBugReq(v OneofBugReq0) OneofBugReq {
-	var s OneofBugReq
-	s.SetOneofBugReq0(v)
-	return s
+// IsOneVariantHasNoUniqueFields0 reports whether OneVariantHasNoUniqueFields is OneVariantHasNoUniqueFields0.
+func (s OneVariantHasNoUniqueFields) IsOneVariantHasNoUniqueFields0() bool {
+	return s.Type == OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields
 }
 
-// SetOneofBugReq1 sets OneofBugReq to OneofBugReq1.
-func (s *OneofBugReq) SetOneofBugReq1(v OneofBugReq1) {
-	s.Type = OneofBugReq1OneofBugReq
-	s.OneofBugReq1 = v
+// IsOneVariantHasNoUniqueFields1 reports whether OneVariantHasNoUniqueFields is OneVariantHasNoUniqueFields1.
+func (s OneVariantHasNoUniqueFields) IsOneVariantHasNoUniqueFields1() bool {
+	return s.Type == OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields
 }
 
-// GetOneofBugReq1 returns OneofBugReq1 and true boolean if OneofBugReq is OneofBugReq1.
-func (s OneofBugReq) GetOneofBugReq1() (v OneofBugReq1, ok bool) {
-	if !s.IsOneofBugReq1() {
-		return v, false
-	}
-	return s.OneofBugReq1, true
-}
-
-// NewOneofBugReq1OneofBugReq returns new OneofBugReq from OneofBugReq1.
-func NewOneofBugReq1OneofBugReq(v OneofBugReq1) OneofBugReq {
-	var s OneofBugReq
-	s.SetOneofBugReq1(v)
-	return s
+// SetOneVariantHasNoUniqueFields0 sets OneVariantHasNoUniqueFields to OneVariantHasNoUniqueFields0.
+func (s *OneVariantHasNoUniqueFields) SetOneVariantHasNoUniqueFields0(v OneVariantHasNoUniqueFields0) {
+	s.Type = OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields
+	s.OneVariantHasNoUniqueFields0 = v
 }
 
-// SetOneofBugReq2 sets OneofBugReq to OneofBugReq2.
-func (s *OneofBugReq) SetOneofBugReq2(v OneofBugReq2) {
-	s.Type = OneofBugReq2OneofBugReq
-	s.OneofBugReq2 = v
-}
-
-// GetOneofBugReq2 returns OneofBugReq2 and true boolean if OneofBugReq is OneofBugReq2.
-func (s OneofBugReq) GetOneofBugReq2() (v OneofBugReq2, ok bool) {
-	if !s.IsOneofBugReq2() {
+// GetOneVariantHasNoUniqueFields0 returns OneVariantHasNoUniqueFields0 and true boolean if OneVariantHasNoUniqueFields is OneVariantHasNoUniqueFields0.
+func (s OneVariantHasNoUniqueFields) GetOneVariantHasNoUniqueFields0() (v OneVariantHasNoUniqueFields0, ok bool) {
+	if !s.IsOneVariantHasNoUniqueFields0() {
 		return v, false
 	}
-	return s.OneofBugReq2, true
+	return s.OneVariantHasNoUniqueFields0, true
 }
 
-// NewOneofBugReq2OneofBugReq returns new OneofBugReq from OneofBugReq2.
-func NewOneofBugReq2OneofBugReq(v OneofBugReq2) OneofBugReq {
-	var s OneofBugReq
-	s.SetOneofBugReq2(v)
+// NewOneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields returns new OneVariantHasNoUniqueFields from OneVariantHasNoUniqueFields0.
+func NewOneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields(v OneVariantHasNoUniqueFields0) OneVariantHasNoUniqueFields {
+	var s OneVariantHasNoUniqueFields
+	s.SetOneVariantHasNoUniqueFields0(v)
 	return s
 }
 
-// SetOneofBugReq3 sets OneofBugReq to OneofBugReq3.
-func (s *OneofBugReq) SetOneofBugReq3(v OneofBugReq3) {
-	s.Type = OneofBugReq3OneofBugReq
-	s.OneofBugReq3 = v
+// SetOneVariantHasNoUniqueFields1 sets OneVariantHasNoUniqueFields to OneVariantHasNoUniqueFields1.
+func (s *OneVariantHasNoUniqueFields) SetOneVariantHasNoUniqueFields1(v OneVariantHasNoUniqueFields1) {
+	s.Type = OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields
+	s.OneVariantHasNoUniqueFields1 = v
 }
 
-// GetOneofBugReq3 returns OneofBugReq3 and true boolean if OneofBugReq is OneofBugReq3.
-func (s OneofBugReq) GetOneofBugReq3() (v OneofBugReq3, ok bool) {
-	if !s.IsOneofBugReq3() {
+// GetOneVariantHasNoUniqueFields1 returns OneVariantHasNoUniqueFields1 and true boolean if OneVariantHasNoUniqueFields is OneVariantHasNoUniqueFields1.
+func (s OneVariantHasNoUniqueFields) GetOneVariantHasNoUniqueFields1() (v OneVariantHasNoUniqueFields1, ok bool) {
+	if !s.IsOneVariantHasNoUniqueFields1() {
 		return v, false
 	}
-	return s.OneofBugReq3, true
+	return s.OneVariantHasNoUniqueFields1, true
 }
 
-// NewOneofBugReq3OneofBugReq returns new OneofBugReq from OneofBugReq3.
-func NewOneofBugReq3OneofBugReq(v OneofBugReq3) OneofBugReq {
-	var s OneofBugReq
-	s.SetOneofBugReq3(v)
+// NewOneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields returns new OneVariantHasNoUniqueFields from OneVariantHasNoUniqueFields1.
+func NewOneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields(v OneVariantHasNoUniqueFields1) OneVariantHasNoUniqueFields {
+	var s OneVariantHasNoUniqueFields
+	s.SetOneVariantHasNoUniqueFields1(v)
 	return s
 }
 
-type OneofBugReq0 struct {
-	CommonMinus1 string `json:"common-1"`
-	CommonMinus2 int    `json:"common-2"`
-	UniqueMinus1 string `json:"unique-1"`
-}
-
-type OneofBugReq1 struct {
-	CommonMinus1 string `json:"common-1"`
-	CommonMinus2 int    `json:"common-2"`
-	UniqueMinus2 string `json:"unique-2"`
+type OneVariantHasNoUniqueFields0 struct {
+	A string `json:"a"`
+	B OptInt `json:"b"`
+	C string `json:"c"`
 }
 
-type OneofBugReq2 struct {
-	CommonMinus1 string `json:"common-1"`
-	CommonMinus2 int    `json:"common-2"`
-	CommonMinus3 OptInt `json:"common-3"`
-	UniqueMinus3 string `json:"unique-3"`
+type OneVariantHasNoUniqueFields1 struct {
+	A string `json:"a"`
+	B OptInt `json:"b"`
+	C string `json:"c"`
+	D OptInt `json:"d"`
 }
 
-type OneofBugReq3 struct {
-	CommonMinus3 OptInt `json:"common-3"`
-	UniqueMinus4 string `json:"unique-4"`
-}
+// OneofBugOK is response for OneofBug operation.
+type OneofBugOK struct{}
 
 // NewOptArrayTest returns new OptArrayTest with value set to v.
 func NewOptArrayTest(v ArrayTest) OptArrayTest {
diff --git a/internal/sample_api/oas_server_gen.go b/internal/sample_api/oas_server_gen.go
index 53502cbe..f575c072 100644
--- a/internal/sample_api/oas_server_gen.go
+++ b/internal/sample_api/oas_server_gen.go
@@ -103,7 +103,7 @@ type Handler interface {
 	// OneofBug implements oneofBug operation.
 	//
 	// POST /oneofBug
-	OneofBug(ctx context.Context, req OneofBugReq) (OneofBugOK, error)
+	OneofBug(ctx context.Context, req OneOfBugs) (OneofBugOK, error)
 	// PetCreate implements petCreate operation.
 	//
 	// Creates pet.


Test patch:
diff --git a/_testdata/sample.json b/_testdata/sample.json
index 704fa0e5..d5b39813 100644
--- a/_testdata/sample.json
+++ b/_testdata/sample.json
@@ -563,44 +563,7 @@
           "content": {
             "application/json": {
               "schema": {
-                "oneOf": [
-                  {
-                    "type": "object",
-                    "required": ["common-1", "common-2", "unique-1"],
-                    "properties": {
-                      "common-1": {"type": "string"},
-                      "common-2": {"type": "integer"},
-                      "unique-1": {"type": "string"}
-                    }
-                  },
-                  {
-                    "type": "object",
-                    "required": ["common-1", "common-2", "unique-2"],
-                    "properties": {
-                      "common-1": {"type": "string"},
-                      "common-2": {"type": "integer"},
-                      "unique-2": {"type": "string"}
-                    }
-                  },
-                  {
-                    "type": "object",
-                    "required": ["common-1", "common-2", "unique-3"],
-                    "properties": {
-                      "common-1": {"type": "string"},
-                      "common-2": {"type": "integer"},
-                      "common-3": {"type": "integer"},
-                      "unique-3": {"type": "string"}
-                    }
-                  },
-                  {
-                    "type": "object",
-                    "required": ["common-1", "common-2", "unique-4"],
-                    "properties": {
-                      "common-3": {"type": "integer"},
-                      "unique-4": {"type": "string"}
-                    }
-                  }
-                ]
+                "$ref": "#/components/schemas/OneOfBugs"
               }
             }
           }
@@ -974,6 +937,84 @@
             "maxLength": 64
           }
         }
+      },
+      "Issue143": {
+        "oneOf": [
+          {
+            "type": "object",
+            "required": ["common-1", "common-2", "unique-1"],
+            "properties": {
+              "common-1": {"type": "string"},
+              "common-2": {"type": "integer"},
+              "unique-1": {"type": "string"}
+            }
+          },
+          {
+            "type": "object",
+            "required": ["common-1", "common-2", "unique-2"],
+            "properties": {
+              "common-1": {"type": "string"},
+              "common-2": {"type": "integer"},
+              "unique-2": {"type": "string"}
+            }
+          },
+          {
+            "type": "object",
+            "required": ["common-1", "common-2", "unique-3"],
+            "properties": {
+              "common-1": {"type": "string"},
+              "common-2": {"type": "integer"},
+              "common-3": {"type": "integer"},
+              "unique-3": {"type": "string"}
+            }
+          },
+          {
+            "type": "object",
+            "required": ["common-1", "common-2", "unique-4"],
+            "properties": {
+              "common-3": {"type": "integer"},
+              "unique-4": {"type": "string"}
+            }
+          }
+        ]
+      },
+      "OneVariantHasNoUniqueFields": {
+        "oneOf": [
+          {
+            "type": "object",
+            "required": ["a", "c"],
+            "properties": {
+              "a": {"type": "string"},
+              "b": {"type": "integer"},
+              "c": {"type": "string"}
+            }
+          },
+          {
+            "type": "object",
+            "required": ["a", "c"],
+            "properties": {
+              "a": {"type": "string"},
+              "b": {"type": "integer"},
+              "c": {"type": "string"},
+              "d": {"type": "integer"}
+            }
+          }
+        ]
+      },
+      "OneOfBugs" : {
+        "type": "object",
+        "required": [
+          "issue143",
+          "additional-fields"
+        ],
+        "properties": {
+          "issue143":{
+            "$ref": "#/components/schemas/Issue143"
+          },
+          "additional-fields": {
+            "$ref": "#/components/schemas/OneVariantHasNoUniqueFields"
+          }
+        }
       }
     },
     "parameters": {
diff --git a/e2e_test.go b/e2e_test.go
index ea97817e..a8b7e380 100644
--- a/e2e_test.go
+++ b/e2e_test.go
@@ -209,7 +209,7 @@ func (s *sampleAPIServer) TestObjectQueryParameter(ctx context.Context, params a
 	return api.TestObjectQueryParameterOK{}, errors.New("invalid input")
 }
 
-func (s sampleAPIServer) OneofBug(ctx context.Context, req api.OneofBugReq) (api.OneofBugOK, error) {
+func (s sampleAPIServer) OneofBug(ctx context.Context, req api.OneOfBugs) (api.OneofBugOK, error) {
 	panic("implement me")
 }
 
diff --git a/json_test.go b/json_test.go
index 80458009..a945deec 100644
--- a/json_test.go
+++ b/json_test.go
@@ -431,26 +431,56 @@ func TestJSONNullableEnum(t *testing.T) {
 }
 
 func TestJSONSum(t *testing.T) {
-	for i, tc := range []struct {
-		Input    string
-		Expected api.OneofBugReqType
-		Error    bool
-	}{
-		{`{"common-1": "abc", "common-2": 1, "unique-1": "unique"}`, api.OneofBugReq0OneofBugReq, false},
-		{`{"common-1": "abc", "common-2": 1, "unique-2": "unique"}`, api.OneofBugReq1OneofBugReq, false},
-		{`{"common-1": "abc", "common-2": 1, "unique-3": "unique"}`, api.OneofBugReq2OneofBugReq, false},
-		{`{"common-1": "abc", "common-2": 1, "unique-4": "unique"}`, api.OneofBugReq3OneofBugReq, false},
-	} {
-		// Make range value copy to prevent data races.
-		tc := tc
-		t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
-			checker := require.NoError
-			if tc.Error {
-				checker = require.Error
-			}
-			r := api.OneofBugReq{}
-			checker(t, r.Decode(jx.DecodeStr(tc.Input)))
-			require.Equal(t, tc.Expected, r.Type)
-		})
-	}
+	t.Run("Issue143", func(t *testing.T) {
+		for i, tc := range []struct {
+			Input    string
+			Expected api.Issue143Type
+			Error    bool
+		}{
+			{`{"common-1": "abc", "common-2": 1, "unique-1": "unique"}`, api.Issue1430Issue143, false},
+			{`{"common-1": "abc", "common-2": 1, "unique-2": "unique"}`, api.Issue1431Issue143, false},
+			{`{"common-1": "abc", "common-2": 1, "unique-3": "unique"}`, api.Issue1432Issue143, false},
+			{`{"common-1": "abc", "common-2": 1, "unique-4": "unique"}`, api.Issue1433Issue143, false},
+		} {
+			// Make range value copy to prevent data races.
+			tc := tc
+			t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
+				checker := require.NoError
+				if tc.Error {
+					checker = require.Error
+				}
+				r := api.Issue143{}
+				checker(t, r.Decode(jx.DecodeStr(tc.Input)))
+				require.Equal(t, tc.Expected, r.Type)
+			})
+		}
+	})
+	t.Run("OneVariantHasNoUniqueFields", func(t *testing.T) {
+		for i, tc := range []struct {
+			Input    string
+			Expected api.OneVariantHasNoUniqueFieldsType
+			Error    bool
+		}{
+			{`{"a": "a", "c": "c"}`,
+				api.OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields, false},
+			{`{"a": "a", "b": 10, "c": "c"}`,
+				api.OneVariantHasNoUniqueFields0OneVariantHasNoUniqueFields, false},
+			{`{"a": "a", "c": "c", "d": 10}`,
+				api.OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields, false},
+			{`{"a": "a", "b": 10, "c": "c", "d": 10}`,
+				api.OneVariantHasNoUniqueFields1OneVariantHasNoUniqueFields, false},
+		} {
+			// Make range value copy to prevent data races.
+			tc := tc
+			t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
+				checker := require.NoError
+				if tc.Error {
+					checker = require.Error
+				}
+				r := api.OneVariantHasNoUniqueFields{}
+				checker(t, r.Decode(jx.DecodeStr(tc.Input)))
+				require.Equal(t, tc.Expected, r.Type)
+			})
+		}
+	})
 }