diff --git a/openapi.yaml b/openapi.yaml index 3243d1c..70d2b51 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -62,7 +62,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Submission" + $ref: "#/components/schemas/Id" default: description: General Error content: @@ -186,6 +186,12 @@ paths: $ref: "#/components/schemas/Error" components: schemas: + Id: + type: object + properties: + ID: + type: integer + format: int64 User: type: object properties: diff --git a/pkg/api/oas_client_gen.go b/pkg/api/oas_client_gen.go index cef6955..38e1cd5 100644 --- a/pkg/api/oas_client_gen.go +++ b/pkg/api/oas_client_gen.go @@ -28,7 +28,7 @@ type Invoker interface { // Create new submission. // // POST /submissions - CreateSubmission(ctx context.Context) (*Submission, error) + CreateSubmission(ctx context.Context) (*ID, error) // GetSubmission invokes getSubmission operation. // // Retrieve map with ID. @@ -118,12 +118,12 @@ func (c *Client) requestURL(ctx context.Context) *url.URL { // Create new submission. // // POST /submissions -func (c *Client) CreateSubmission(ctx context.Context) (*Submission, error) { +func (c *Client) CreateSubmission(ctx context.Context) (*ID, error) { res, err := c.sendCreateSubmission(ctx) return res, err } -func (c *Client) sendCreateSubmission(ctx context.Context) (res *Submission, err error) { +func (c *Client) sendCreateSubmission(ctx context.Context) (res *ID, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createSubmission"), semconv.HTTPRequestMethodKey.String("POST"), diff --git a/pkg/api/oas_handlers_gen.go b/pkg/api/oas_handlers_gen.go index c44efe8..c8b22fe 100644 --- a/pkg/api/oas_handlers_gen.go +++ b/pkg/api/oas_handlers_gen.go @@ -65,7 +65,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool, err error ) - var response *Submission + var response *ID if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, @@ -80,7 +80,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool, type ( Request = struct{} Params = struct{} - Response = *Submission + Response = *ID ) response, err = middleware.HookMiddleware[ Request, diff --git a/pkg/api/oas_json_gen.go b/pkg/api/oas_json_gen.go index 7ab9de0..efde54a 100644 --- a/pkg/api/oas_json_gen.go +++ b/pkg/api/oas_json_gen.go @@ -125,6 +125,69 @@ func (s *Error) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *ID) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ID) encodeFields(e *jx.Encoder) { + { + if s.ID.Set { + e.FieldStart("ID") + s.ID.Encode(e) + } + } +} + +var jsonFieldsNameOfID = [1]string{ + 0: "ID", +} + +// Decode decodes ID from json. +func (s *ID) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ID to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "ID": + if err := func() error { + s.ID.Reset() + if err := s.ID.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ID\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode ID") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *ID) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ID) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes bool as json. func (o OptBool) Encode(e *jx.Encoder) { if !o.Set { diff --git a/pkg/api/oas_response_decoders_gen.go b/pkg/api/oas_response_decoders_gen.go index 8e53340..02ca7ea 100644 --- a/pkg/api/oas_response_decoders_gen.go +++ b/pkg/api/oas_response_decoders_gen.go @@ -14,7 +14,7 @@ import ( "github.com/ogen-go/ogen/validate" ) -func decodeCreateSubmissionResponse(resp *http.Response) (res *Submission, _ error) { +func decodeCreateSubmissionResponse(resp *http.Response) (res *ID, _ error) { switch resp.StatusCode { case 200: // Code 200. @@ -30,7 +30,7 @@ func decodeCreateSubmissionResponse(resp *http.Response) (res *Submission, _ err } d := jx.DecodeBytes(buf) - var response Submission + var response ID if err := func() error { if err := response.Decode(d); err != nil { return err diff --git a/pkg/api/oas_response_encoders_gen.go b/pkg/api/oas_response_encoders_gen.go index 3e1e666..e938130 100644 --- a/pkg/api/oas_response_encoders_gen.go +++ b/pkg/api/oas_response_encoders_gen.go @@ -13,7 +13,7 @@ import ( ht "github.com/ogen-go/ogen/http" ) -func encodeCreateSubmissionResponse(response *Submission, w http.ResponseWriter, span trace.Span) error { +func encodeCreateSubmissionResponse(response *ID, w http.ResponseWriter, span trace.Span) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) span.SetStatus(codes.Ok, http.StatusText(200)) diff --git a/pkg/api/oas_schemas_gen.go b/pkg/api/oas_schemas_gen.go index b517dd6..3f84df4 100644 --- a/pkg/api/oas_schemas_gen.go +++ b/pkg/api/oas_schemas_gen.go @@ -63,6 +63,21 @@ func (s *ErrorStatusCode) SetResponse(val Error) { s.Response = val } +// Ref: #/components/schemas/Id +type ID struct { + ID OptInt64 `json:"ID"` +} + +// GetID returns the value of ID. +func (s *ID) GetID() OptInt64 { + return s.ID +} + +// SetID sets the value of ID. +func (s *ID) SetID(val OptInt64) { + s.ID = val +} + // NewOptBool returns new OptBool with value set to v. func NewOptBool(v bool) OptBool { return OptBool{ diff --git a/pkg/api/oas_server_gen.go b/pkg/api/oas_server_gen.go index 296f9e2..af27b39 100644 --- a/pkg/api/oas_server_gen.go +++ b/pkg/api/oas_server_gen.go @@ -13,7 +13,7 @@ type Handler interface { // Create new submission. // // POST /submissions - CreateSubmission(ctx context.Context) (*Submission, error) + CreateSubmission(ctx context.Context) (*ID, error) // GetSubmission implements getSubmission operation. // // Retrieve map with ID. diff --git a/pkg/api/oas_unimplemented_gen.go b/pkg/api/oas_unimplemented_gen.go index 335d38c..3c6954a 100644 --- a/pkg/api/oas_unimplemented_gen.go +++ b/pkg/api/oas_unimplemented_gen.go @@ -18,7 +18,7 @@ var _ Handler = UnimplementedHandler{} // Create new submission. // // POST /submissions -func (UnimplementedHandler) CreateSubmission(ctx context.Context) (r *Submission, _ error) { +func (UnimplementedHandler) CreateSubmission(ctx context.Context) (r *ID, _ error) { return r, ht.ErrNotImplemented } diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index f67c879..7534754 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -6,7 +6,7 @@ import ( ) // POST /submissions -func (svc *Service) CreateSubmission(ctx context.Context) (*api.Submission, error) { +func (svc *Service) CreateSubmission(ctx context.Context) (*api.ID, error) { return nil, nil }