From 50f8e60d633dcc097833803b4643e92264981bba Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Tue, 9 Jul 2024 15:32:44 -0400 Subject: [PATCH] Check in generated code (#7) --- .gitignore | 2 - api/islandora.gen.go | 300 +++++++++++++++++++++++++++++++++++++ workbench/impl.go | 9 +- workbench/workbench.gen.go | 228 ++++++++++++++++++++++++++++ 4 files changed, 531 insertions(+), 8 deletions(-) create mode 100644 api/islandora.gen.go create mode 100644 workbench/workbench.gen.go diff --git a/.gitignore b/.gitignore index 2756db5..43b3144 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,3 @@ workbench.yaml output.json go-islandora islandora-starter-site -api/islandora.gen.go -workbench/workbench.gen.go diff --git a/api/islandora.gen.go b/api/islandora.gen.go new file mode 100644 index 0000000..f0949fc --- /dev/null +++ b/api/islandora.gen.go @@ -0,0 +1,300 @@ +//go:build go1.22 + +// Package api provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT. +package api + +import ( + "fmt" + "net/http" + + islandoraModel "github.com/lehigh-university-libraries/go-islandora/model" +) + +// IslandoraObject defines model for IslandoraObject. +type IslandoraObject struct { + Changed *islandoraModel.GenericField `json:"changed,omitempty"` + Created *islandoraModel.GenericField `json:"created,omitempty"` + FieldAbstract *islandoraModel.TypedTextField `json:"field_abstract,omitempty"` + FieldAccess *islandoraModel.GenericField `json:"field_access,omitempty"` + FieldAffiliatedInstitution *islandoraModel.EntityReferenceField `json:"field_affiliated_institution,omitempty"` + FieldAltTitle *islandoraModel.GenericField `json:"field_alt_title,omitempty"` + FieldClassification *islandoraModel.GenericField `json:"field_classification,omitempty"` + FieldCollectionHierarchy *islandoraModel.EntityReferenceField `json:"field_collection_hierarchy,omitempty"` + FieldCoordinates *islandoraModel.GeoLocationField `json:"field_coordinates,omitempty"` + FieldCoordinatesText *islandoraModel.GenericField `json:"field_coordinates_text,omitempty"` + + // FieldCopyrightDate Date of copyright of the resource. + FieldCopyrightDate *islandoraModel.EdtfField `json:"field_copyright_date,omitempty"` + FieldCreatorDescription *islandoraModel.GenericField `json:"field_creator_description,omitempty"` + FieldCreatorEmail *islandoraModel.EmailField `json:"field_creator_email,omitempty"` + FieldCreatorRole *islandoraModel.EntityReferenceField `json:"field_creator_role,omitempty"` + + // FieldDateModified Date on which the original resource being represented in Islandora was changed. Typically modification dates of digital representations of the resource stored in Islandora will be recorded on the relevant Media instead of here. + FieldDateModified *islandoraModel.EdtfField `json:"field_date_modified,omitempty"` + FieldDateOther *islandoraModel.TypedTextField `json:"field_date_other,omitempty"` + FieldDateSeason *islandoraModel.EntityReferenceField `json:"field_date_season,omitempty"` + + // FieldDateValid Date (often a range) of validity of a resource. + FieldDateValid *islandoraModel.EdtfField `json:"field_date_valid,omitempty"` + FieldDegreeLevel *islandoraModel.EntityReferenceField `json:"field_degree_level,omitempty"` + FieldDegreeName *islandoraModel.EntityReferenceField `json:"field_degree_name,omitempty"` + FieldDepartmentName *islandoraModel.EntityReferenceField `json:"field_department_name,omitempty"` + FieldDescription *islandoraModel.GenericField `json:"field_description,omitempty"` + FieldDigitalFormat *islandoraModel.EntityReferenceField `json:"field_digital_format,omitempty"` + FieldDigitalOrigin *islandoraModel.EntityReferenceField `json:"field_digital_origin,omitempty"` + FieldDisplayHints *islandoraModel.EntityReferenceField `json:"field_display_hints,omitempty"` + FieldEdition *islandoraModel.GenericField `json:"field_edition,omitempty"` + + // FieldEdtfDate A date without a type or relationship to the resource specified + FieldEdtfDate *islandoraModel.EdtfField `json:"field_edtf_date,omitempty"` + FieldEdtfDateCaptured *islandoraModel.EdtfField `json:"field_edtf_date_captured,omitempty"` + + // FieldEdtfDateCreated Date of creation of the resource + FieldEdtfDateCreated *islandoraModel.EdtfField `json:"field_edtf_date_created,omitempty"` + FieldEdtfDateEmbargo *islandoraModel.EdtfField `json:"field_edtf_date_embargo,omitempty"` + + // FieldEdtfDateIssued Date of formal issuance of the resource. This includes publication dates. + FieldEdtfDateIssued *islandoraModel.EdtfField `json:"field_edtf_date_issued,omitempty"` + FieldExtent *islandoraModel.TypedTextField `json:"field_extent,omitempty"` + FieldFrequency *islandoraModel.EntityReferenceField `json:"field_frequency,omitempty"` + + // FieldFullTitle If the full resource title is longer than 255 characters and you truncated it in the required Title field above, record the full title here. + FieldFullTitle *islandoraModel.GenericField `json:"field_full_title,omitempty"` + + // FieldGenre A term or terms that designate a category characterizing a particular style, form, or content, such as artistic, musical, literary composition, etc. + FieldGenre *islandoraModel.EntityReferenceField `json:"field_genre,omitempty"` + FieldGeographicSubject *islandoraModel.EntityReferenceField `json:"field_geographic_subject,omitempty"` + FieldHideGscholarMetatags *islandoraModel.BoolField `json:"field_hide_gscholar_metatags,omitempty"` + FieldHideHocr *islandoraModel.BoolField `json:"field_hide_hocr,omitempty"` + FieldIdentifier *islandoraModel.TypedTextField `json:"field_identifier,omitempty"` + FieldKeywords *islandoraModel.EntityReferenceField `json:"field_keywords,omitempty"` + + // FieldLanguage Language of the resource content + FieldLanguage *islandoraModel.EntityReferenceField `json:"field_language,omitempty"` + FieldLccClassification *islandoraModel.GenericField `json:"field_lcc_classification,omitempty"` + FieldLcshTopic *islandoraModel.EntityReferenceField `json:"field_lcsh_topic,omitempty"` + + // FieldLinkedAgent Names of entities having some relationship to the resource, and, optionally, the relationship to the resource. If a relationship is not specified, it will be recorded as Attributed Name in the system's linked data representation.
+ // Publisher/manufacturer/distributor/etc. name is recorded here, with the appropriate relationship specified.
+ // This field does not allow creating names of entities on the fly. First create a person, family, or corporate body, then link it here. + FieldLinkedAgent *islandoraModel.TypedRelationField `json:"field_linked_agent,omitempty"` + FieldLocalRestriction *islandoraModel.BoolField `json:"field_local_restriction,omitempty"` + FieldMediaType *islandoraModel.EntityReferenceField `json:"field_media_type,omitempty"` + + // FieldMemberOf This item's parent item in Islandora. Usually this will be a collection or compound object. + FieldMemberOf *islandoraModel.EntityReferenceField `json:"field_member_of,omitempty"` + FieldModeOfIssuance *islandoraModel.EntityReferenceField `json:"field_mode_of_issuance,omitempty"` + + // FieldModel The internal-to-Islandora category of the resource. Affects how the item is displayed/viewed. + FieldModel *islandoraModel.EntityReferenceField `json:"field_model,omitempty"` + FieldNote *islandoraModel.TypedTextField `json:"field_note,omitempty"` + FieldOriginalTitle *islandoraModel.GenericField `json:"field_original_title,omitempty"` + FieldPartDetail *islandoraModel.PartDetailField `json:"field_part_detail,omitempty"` + FieldPhysicalDescription *islandoraModel.TypedTextField `json:"field_physical_description,omitempty"` + + // FieldPhysicalForm The physical format of the original resource being described. If the resource is a physical object, the physical form is recorded here. If the resource is born-digital, the original digital form is recorded here. Details of the formats of resource representations stored in Islandora should be recorded on the relevant Media files. + FieldPhysicalForm *islandoraModel.EntityReferenceField `json:"field_physical_form,omitempty"` + FieldPhysicalLocation *islandoraModel.EntityReferenceField `json:"field_physical_location,omitempty"` + + // FieldPid PID of this object in Islandora 7.x (applies to migrated objects only) + FieldPid *islandoraModel.GenericField `json:"field_pid,omitempty"` + FieldPlacePublished *islandoraModel.GenericField `json:"field_place_published,omitempty"` + FieldPlacePublishedCountry *islandoraModel.EntityReferenceField `json:"field_place_published_country,omitempty"` + FieldPublisher *islandoraModel.GenericField `json:"field_publisher,omitempty"` + FieldRecordOrigin *islandoraModel.GenericField `json:"field_record_origin,omitempty"` + FieldRelatedItem *islandoraModel.RelatedItemField `json:"field_related_item,omitempty"` + FieldRelation *islandoraModel.GenericField `json:"field_relation,omitempty"` + + // FieldResourceType The general nature or genre of the content of the resource. To describe the digital or physical format of the resource, use Form instead. + FieldResourceType *islandoraModel.EntityReferenceField `json:"field_resource_type,omitempty"` + FieldRights *islandoraModel.GenericField `json:"field_rights,omitempty"` + FieldSiteDisposition *islandoraModel.EntityReferenceField `json:"field_site_disposition,omitempty"` + FieldSortBy *islandoraModel.GenericField `json:"field_sort_by,omitempty"` + FieldSource *islandoraModel.GenericField `json:"field_source,omitempty"` + + // FieldSubject If using separate fields to record topical, geographic, name, and temporal subjects, record topical subjects here. If not splitting subjects into to different fields, all subjects can be recorded in this field. + FieldSubject *islandoraModel.EntityReferenceField `json:"field_subject,omitempty"` + + // FieldSubjectGeneral General subjects which may include topical, geographic, temporal, and genre elements. If you wish to manage these types of subjects separately, use the more specific Subject fields.

Any new term added by typing it here will be added to the Subject taxonomy. If you need to create a new term in another taxonomy, do Structure > Taxonomy > [the appropriate taxonomy] > Add terms to add terms. You may need to save this form and reload it for your terms to be available here. + FieldSubjectGeneral *islandoraModel.EntityReferenceField `json:"field_subject_general,omitempty"` + FieldSubjectHierarchicalGeo *islandoraModel.HierarchicalGeographicField `json:"field_subject_hierarchical_geo,omitempty"` + FieldSubjectLcsh *islandoraModel.EntityReferenceField `json:"field_subject_lcsh,omitempty"` + + // FieldSubjectsName Any new term added by typing it here will be added to the Person taxonomy. If you need to create a new Corporate Body or Family taxonomy term, do Structure > Taxonomy > [the appropriate taxonomy] > Add terms to add terms. You may need to save this form and reload it for your terms to be available here. + FieldSubjectsName *islandoraModel.EntityReferenceField `json:"field_subjects_name,omitempty"` + FieldTableOfContents *islandoraModel.GenericField `json:"field_table_of_contents,omitempty"` + FieldTemporalSubject *islandoraModel.EntityReferenceField `json:"field_temporal_subject,omitempty"` + + // FieldThumbnail Appears as a thumbnail on “Card” views and as a representative image on article pages. This field is automatically populated by the thumbnail created on the node. But if you want to reference a thumbnail from another node, you can reference it here. + FieldThumbnail *islandoraModel.EntityReferenceField `json:"field_thumbnail,omitempty"` + FieldTitlePartName *islandoraModel.GenericField `json:"field_title_part_name,omitempty"` + + // FieldViewerOverride Select an alternate viewer, if desired for this resource. + FieldViewerOverride *islandoraModel.EntityReferenceField `json:"field_viewer_override,omitempty"` + + // FieldWeight Enter numeric values to force a custom sort order within a collection of resources. See external documentation for the Weight module. + FieldWeight *islandoraModel.IntField `json:"field_weight,omitempty"` + Language *islandoraModel.GenericField `json:"language,omitempty"` + Nid *islandoraModel.IntField `json:"nid,omitempty"` + RevisionLog *islandoraModel.GenericField `json:"revision_log,omitempty"` + RevisionTimestamp *islandoraModel.GenericField `json:"revision_timestamp,omitempty"` + RevisionUid *islandoraModel.EntityReferenceField `json:"revision_uid,omitempty"` + Status *islandoraModel.BoolField `json:"status,omitempty"` + Title *islandoraModel.GenericField `json:"title,omitempty"` + Type *islandoraModel.ConfigReferenceField `json:"type,omitempty"` + Uid *islandoraModel.EntityReferenceField `json:"uid,omitempty"` + Uuid *islandoraModel.GenericField `json:"uuid,omitempty"` + Vid *islandoraModel.IntField `json:"vid,omitempty"` +} + +// ServerInterface represents all server handlers. +type ServerInterface interface { + // Upload CSV file + // (POST /upload) + PostUpload(w http.ResponseWriter, r *http.Request) +} + +// ServerInterfaceWrapper converts contexts to parameters. +type ServerInterfaceWrapper struct { + Handler ServerInterface + HandlerMiddlewares []MiddlewareFunc + ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) +} + +type MiddlewareFunc func(http.Handler) http.Handler + +// PostUpload operation middleware +func (siw *ServerInterfaceWrapper) PostUpload(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.PostUpload(w, r) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +type UnescapedCookieParamError struct { + ParamName string + Err error +} + +func (e *UnescapedCookieParamError) Error() string { + return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName) +} + +func (e *UnescapedCookieParamError) Unwrap() error { + return e.Err +} + +type UnmarshalingParamError struct { + ParamName string + Err error +} + +func (e *UnmarshalingParamError) Error() string { + return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error()) +} + +func (e *UnmarshalingParamError) Unwrap() error { + return e.Err +} + +type RequiredParamError struct { + ParamName string +} + +func (e *RequiredParamError) Error() string { + return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName) +} + +type RequiredHeaderError struct { + ParamName string + Err error +} + +func (e *RequiredHeaderError) Error() string { + return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName) +} + +func (e *RequiredHeaderError) Unwrap() error { + return e.Err +} + +type InvalidParamFormatError struct { + ParamName string + Err error +} + +func (e *InvalidParamFormatError) Error() string { + return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error()) +} + +func (e *InvalidParamFormatError) Unwrap() error { + return e.Err +} + +type TooManyValuesForParamError struct { + ParamName string + Count int +} + +func (e *TooManyValuesForParamError) Error() string { + return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count) +} + +// Handler creates http.Handler with routing matching OpenAPI spec. +func Handler(si ServerInterface) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{}) +} + +type StdHTTPServerOptions struct { + BaseURL string + BaseRouter *http.ServeMux + Middlewares []MiddlewareFunc + ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) +} + +// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux. +func HandlerFromMux(si ServerInterface, m *http.ServeMux) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{ + BaseRouter: m, + }) +} + +func HandlerFromMuxWithBaseURL(si ServerInterface, m *http.ServeMux, baseURL string) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{ + BaseURL: baseURL, + BaseRouter: m, + }) +} + +// HandlerWithOptions creates http.Handler with additional options +func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler { + m := options.BaseRouter + + if m == nil { + m = http.NewServeMux() + } + if options.ErrorHandlerFunc == nil { + options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) { + http.Error(w, err.Error(), http.StatusBadRequest) + } + } + + wrapper := ServerInterfaceWrapper{ + Handler: si, + HandlerMiddlewares: options.Middlewares, + ErrorHandlerFunc: options.ErrorHandlerFunc, + } + + m.HandleFunc("POST "+options.BaseURL+"/upload", wrapper.PostUpload) + + return m +} diff --git a/workbench/impl.go b/workbench/impl.go index eb4fed0..3fe1fe6 100644 --- a/workbench/impl.go +++ b/workbench/impl.go @@ -18,12 +18,9 @@ func NewServer() Server { func (Server) PostUpload(w http.ResponseWriter, r *http.Request) { // TODO: transform the vanilla CSV into workbench CSV - resp := IslandoraObject{ - Title: &islandoraModel.GenericField{ - islandoraModel.Generic{ - Value: "foo", - }, - }, + title := "foo" + resp := SheetsCsv{ + Title: &title, } w.WriteHeader(http.StatusOK) diff --git a/workbench/workbench.gen.go b/workbench/workbench.gen.go new file mode 100644 index 0000000..65e42c4 --- /dev/null +++ b/workbench/workbench.gen.go @@ -0,0 +1,228 @@ +//go:build go1.22 + +// Package workbench provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT. +package workbench + +import ( + "fmt" + "net/http" +) + +// SheetsCsv defines model for SheetsCsv. +type SheetsCsv struct { + Abstract *string `csv:"field_abstract.attr0=abstract" json:"Abstract,omitempty"` + Access *string `csv:"field_access" json:"Access,omitempty"` + AddCoverpageYN *string `csv:"field_add_coverpage" json:"Add Coverpage (Y/N),omitempty"` + ArchivalBox *string `csv:"field_note.attr0=box" json:"Archival Box,omitempty"` + ArchivalCollection *string `csv:"field_note.attr0=collection" json:"Archival Collection,omitempty"` + ArchivalFolder *string `csv:"field_note.attr0=folder" json:"Archival Folder,omitempty"` + ArchivalSeries *string `csv:"field_note.attr0=series" json:"Archival Series,omitempty"` + CallNumber *string `csv:"field_identifier.attr0=call-number" json:"Call Number,omitempty"` + CaptureDevice *string `csv:"field_note.attr0=capture-device" json:"Capture Device,omitempty"` + CatalogOrArchivesSpaceURL *string `csv:"field_identifier.attr0=uri" json:"Catalog or ArchivesSpace URL,omitempty"` + ChildSortOrder *string `csv:"field_weight" json:"Child Sort Order,omitempty"` + ContributorEmail1 *string `csv:"field_linked_agent.entity.field_email" json:"Contributor Email 1,omitempty"` + ContributorInstitution1 *string `csv:"field_linked_agent.entity.field_relationships" json:"Contributor Institution 1,omitempty"` + ContributorName1 *string `csv:"field_linked_agent.name" json:"Contributor Name 1,omitempty"` + ContributorRelator1 *string `csv:"field_linked_agent.rel_type" json:"Contributor Relator 1,omitempty"` + ContributorStatus1 *string `csv:"field_linked_agent.entity.field_contributor_status" json:"Contributor Status 1,omitempty"` + ContributorType1 *string `csv:"field_linked_agent.vid" json:"Contributor Type 1,omitempty"` + CreationDate *string `csv:"field_edtf_date_issued" json:"Creation Date,omitempty"` + DOI *string `csv:"field_identifier.attr0=doi" json:"DOI,omitempty"` + DateCaptured *string `csv:"field_edtf_date_captured" json:"Date Captured,omitempty"` + Description *string `csv:"field_abstract.attr0=description" json:"Description,omitempty"` + DigitalOrigin *string `csv:"field_digital_origin" json:"Digital Origin,omitempty"` + Dimensions *string `csv:"field_extent.attr0=dimensions" json:"Dimensions,omitempty"` + Edition *string `csv:"field_edition" json:"Edition,omitempty"` + EmbargoUntilDate *string `csv:"field_edtf_date_embargo" json:"Embargo Until Date,omitempty"` + FileFormatMIMEType *string `csv:"field_media_type" json:"File Format (MIME Type),omitempty"` + FilePath *string `csv:"file" json:"File Path,omitempty"` + FileSize *string `csv:"field_extent.attr0=bytes" json:"File Size,omitempty"` + FullTitle *string `csv:"field_full_title" json:"Full Title,omitempty"` + GenreGettyAAT *string `csv:"field_genre" json:"Genre (Getty AAT),omitempty"` + HierarchicalGeographicGettyTGN *string `csv:"field_subject_hierarchical_geo" json:"Hierarchical Geographic (Getty TGN),omitempty"` + HumanName *string `csv:"-" json:"Human Name,omitempty"` + IssueNumber *string `csv:"field_part_detail.attr0=issue" json:"Issue Number,omitempty"` + Keyword *string `csv:"field_keywords" json:"Keyword,omitempty"` + Language *string `csv:"field_language" json:"Language,omitempty"` + LocalRestriction *string `csv:"field_local_restriction" json:"Local Restriction,omitempty"` + MakePublicYN *string `csv:"published" json:"Make Public (Y/N),omitempty"` + NodeID *string `csv:"nid" json:"Node ID,omitempty"` + ORCIDNumber1 *string `csv:"field_linked_agent.entity.field_identifier.attr0=orcid" json:"ORCID Number 1,omitempty"` + ObjectModel *string `csv:"field_model" json:"Object Model,omitempty"` + PPI *string `csv:"field_note.attr0=ppi" json:"PPI,omitempty"` + PageCount *string `csv:"field_extent.attr0=page" json:"Page Count,omitempty"` + PageNumbers *string `csv:"field_part_detail.attr0=page" json:"Page Numbers,omitempty"` + PageItemParentID *string `csv:"parent_id" json:"Page/Item Parent ID,omitempty"` + ParentCollection *string `csv:"field_member_of" json:"Parent Collection,omitempty"` + PhysicalFormatGettyAAT *string `csv:"field_physical_form" json:"Physical Format (Getty AAT),omitempty"` + PreferredCitationIncludedOnlyInFritzLabAndEnvironmentalReports *string `csv:"field_note.attr0=preferred-citation" json:"Preferred-Citation (included only in Fritz Lab and Environmental reports),omitempty"` + Publisher *string `csv:"field_publisher" json:"Publisher,omitempty"` + RelatedDepartment *string `csv:"field_department_name" json:"Related Department,omitempty"` + ReportNumberIncludedOnlyOnATLSSAndFritzLabSpreadsheet *string `csv:"field_identifier.attr0=report-number" json:"Report Number (included only on ATLSS and Fritz Lab spreadsheet),omitempty"` + ResourceType *string `csv:"field_resource_type" json:"Resource Type,omitempty"` + RightsStatement *string `csv:"field_rights" json:"Rights Statement,omitempty"` + RunTimeHHMMSS *string `csv:"field_extent.attr0=minutes" json:"Run Time (HH:MM:SS),omitempty"` + Season *string `csv:"field_date_season" json:"Season,omitempty"` + SourcePublicationLISSN *string `csv:"field_related_item.identifier_type=issn" json:"Source Publication L-ISSN,omitempty"` + SourcePublicationTitle *string `csv:"field_related_item.title" json:"Source Publication Title,omitempty"` + SubjectGeographicLCNAF *string `csv:"field_geographic_subject.vid=geographic_naf" json:"Subject Geographic (LCNAF),omitempty"` + SubjectGeographicLocal *string `csv:"field_geographic_subject.vid=geographic_local" json:"Subject Geographic (Local),omitempty"` + SubjectNameLCNAF *string `csv:"field_subjects_name" json:"Subject Name (LCNAF),omitempty"` + SubjectTopicLCSH *string `csv:"field_subject_lcsh" json:"Subject Topic (LCSH),omitempty"` + Title *string `csv:"title" json:"Title,omitempty"` + UploadID *string `csv:"id" json:"Upload ID,omitempty"` + VolumeNumber *string `csv:"field_part_detail.attr0=volume" json:"Volume Number,omitempty"` +} + +// ServerInterface represents all server handlers. +type ServerInterface interface { + // Upload CSV file + // (POST /upload) + PostUpload(w http.ResponseWriter, r *http.Request) +} + +// ServerInterfaceWrapper converts contexts to parameters. +type ServerInterfaceWrapper struct { + Handler ServerInterface + HandlerMiddlewares []MiddlewareFunc + ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) +} + +type MiddlewareFunc func(http.Handler) http.Handler + +// PostUpload operation middleware +func (siw *ServerInterfaceWrapper) PostUpload(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.PostUpload(w, r) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +type UnescapedCookieParamError struct { + ParamName string + Err error +} + +func (e *UnescapedCookieParamError) Error() string { + return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName) +} + +func (e *UnescapedCookieParamError) Unwrap() error { + return e.Err +} + +type UnmarshalingParamError struct { + ParamName string + Err error +} + +func (e *UnmarshalingParamError) Error() string { + return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error()) +} + +func (e *UnmarshalingParamError) Unwrap() error { + return e.Err +} + +type RequiredParamError struct { + ParamName string +} + +func (e *RequiredParamError) Error() string { + return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName) +} + +type RequiredHeaderError struct { + ParamName string + Err error +} + +func (e *RequiredHeaderError) Error() string { + return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName) +} + +func (e *RequiredHeaderError) Unwrap() error { + return e.Err +} + +type InvalidParamFormatError struct { + ParamName string + Err error +} + +func (e *InvalidParamFormatError) Error() string { + return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error()) +} + +func (e *InvalidParamFormatError) Unwrap() error { + return e.Err +} + +type TooManyValuesForParamError struct { + ParamName string + Count int +} + +func (e *TooManyValuesForParamError) Error() string { + return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count) +} + +// Handler creates http.Handler with routing matching OpenAPI spec. +func Handler(si ServerInterface) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{}) +} + +type StdHTTPServerOptions struct { + BaseURL string + BaseRouter *http.ServeMux + Middlewares []MiddlewareFunc + ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) +} + +// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux. +func HandlerFromMux(si ServerInterface, m *http.ServeMux) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{ + BaseRouter: m, + }) +} + +func HandlerFromMuxWithBaseURL(si ServerInterface, m *http.ServeMux, baseURL string) http.Handler { + return HandlerWithOptions(si, StdHTTPServerOptions{ + BaseURL: baseURL, + BaseRouter: m, + }) +} + +// HandlerWithOptions creates http.Handler with additional options +func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler { + m := options.BaseRouter + + if m == nil { + m = http.NewServeMux() + } + if options.ErrorHandlerFunc == nil { + options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) { + http.Error(w, err.Error(), http.StatusBadRequest) + } + } + + wrapper := ServerInterfaceWrapper{ + Handler: si, + HandlerMiddlewares: options.Middlewares, + ErrorHandlerFunc: options.ErrorHandlerFunc, + } + + m.HandleFunc("POST "+options.BaseURL+"/upload", wrapper.PostUpload) + + return m +}