1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

swager generated api

This commit is contained in:
Michael Jerger 2023-11-17 17:20:22 +01:00
parent 07bd30cf20
commit 109dbd7d75
4 changed files with 452 additions and 0 deletions

View file

@ -0,0 +1,85 @@
// Code generated by go-swagger; DO NOT EDIT.
package activitypub
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"code.gitea.io/gitea/modules/log"
)
// New creates a new activitypub API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
return &Client{transport: transport, formats: formats}
}
/*
Client for activitypub API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
// ClientOption is the option for Client methods
type ClientOption func(*runtime.ClientOperation)
// ClientService is the interface for Client methods
type ClientService interface {
ActivitypubPerson(params *ActivitypubPersonParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonOK, error)
SetTransport(transport runtime.ClientTransport)
}
/*
ActivitypubPerson returns the person actor for a user
*/
func (a *Client) ActivitypubPerson(params *ActivitypubPersonParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ActivitypubPersonOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewActivitypubPersonParams()
}
op := &runtime.ClientOperation{
ID: "activitypubPerson",
Method: "GET",
PathPattern: "/activitypub/user-id/{user-id}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json", "text/plain"},
Schemes: []string{"http", "https"},
Params: params,
Reader: &ActivitypubPersonReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*ActivitypubPersonOK)
log.Info("result %v",result)
log.Info("success %v",success)
log.Info("error %v",err)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for activitypubPerson: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View file

@ -0,0 +1,152 @@
// Code generated by go-swagger; DO NOT EDIT.
package activitypub
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// NewActivitypubPersonParams creates a new ActivitypubPersonParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewActivitypubPersonParams() *ActivitypubPersonParams {
return &ActivitypubPersonParams{
timeout: cr.DefaultTimeout,
}
}
// NewActivitypubPersonParamsWithTimeout creates a new ActivitypubPersonParams object
// with the ability to set a timeout on a request.
func NewActivitypubPersonParamsWithTimeout(timeout time.Duration) *ActivitypubPersonParams {
return &ActivitypubPersonParams{
timeout: timeout,
}
}
// NewActivitypubPersonParamsWithContext creates a new ActivitypubPersonParams object
// with the ability to set a context for a request.
func NewActivitypubPersonParamsWithContext(ctx context.Context) *ActivitypubPersonParams {
return &ActivitypubPersonParams{
Context: ctx,
}
}
// NewActivitypubPersonParamsWithHTTPClient creates a new ActivitypubPersonParams object
// with the ability to set a custom HTTPClient for a request.
func NewActivitypubPersonParamsWithHTTPClient(client *http.Client) *ActivitypubPersonParams {
return &ActivitypubPersonParams{
HTTPClient: client,
}
}
/*
ActivitypubPersonParams contains all the parameters to send to the API endpoint
for the activitypub person operation.
Typically these are written to a http.Request.
*/
type ActivitypubPersonParams struct {
/* UserID.
user ID of the user
*/
UserID int64
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the activitypub person params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ActivitypubPersonParams) WithDefaults() *ActivitypubPersonParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the activitypub person params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ActivitypubPersonParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the activitypub person params
func (o *ActivitypubPersonParams) WithTimeout(timeout time.Duration) *ActivitypubPersonParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the activitypub person params
func (o *ActivitypubPersonParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the activitypub person params
func (o *ActivitypubPersonParams) WithContext(ctx context.Context) *ActivitypubPersonParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the activitypub person params
func (o *ActivitypubPersonParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the activitypub person params
func (o *ActivitypubPersonParams) WithHTTPClient(client *http.Client) *ActivitypubPersonParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the activitypub person params
func (o *ActivitypubPersonParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithUserID adds the userID to the activitypub person params
func (o *ActivitypubPersonParams) WithUserID(userID int64) *ActivitypubPersonParams {
o.SetUserID(userID)
return o
}
// SetUserID adds the userId to the activitypub person params
func (o *ActivitypubPersonParams) SetUserID(userID int64) {
o.UserID = userID
}
// WriteToRequest writes these params to a swagger request
func (o *ActivitypubPersonParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param user-id
if err := r.SetPathParam("user-id", swag.FormatInt64(o.UserID)); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,103 @@
// Code generated by go-swagger; DO NOT EDIT.
package activitypub
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
models "github.com/go-ap/activitypub"
)
// ActivitypubPersonReader is a Reader for the ActivitypubPerson structure.
type ActivitypubPersonReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ActivitypubPersonReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewActivitypubPersonOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
return nil, runtime.NewAPIError("[GET /activitypub/user-id/{user-id}] activitypubPerson", response, response.Code())
}
}
// NewActivitypubPersonOK creates a ActivitypubPersonOK with default headers values
func NewActivitypubPersonOK() *ActivitypubPersonOK {
return &ActivitypubPersonOK{}
}
/*
ActivitypubPersonOK describes a response with status code 200, with default header values.
ActivityPub
*/
type ActivitypubPersonOK struct {
Payload *models.Person
}
// IsSuccess returns true when this activitypub person o k response has a 2xx status code
func (o *ActivitypubPersonOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this activitypub person o k response has a 3xx status code
func (o *ActivitypubPersonOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this activitypub person o k response has a 4xx status code
func (o *ActivitypubPersonOK) IsClientError() bool {
return false
}
// IsServerError returns true when this activitypub person o k response has a 5xx status code
func (o *ActivitypubPersonOK) IsServerError() bool {
return false
}
// IsCode returns true when this activitypub person o k response a status code equal to that given
func (o *ActivitypubPersonOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the activitypub person o k response
func (o *ActivitypubPersonOK) Code() int {
return 200
}
func (o *ActivitypubPersonOK) Error() string {
return fmt.Sprintf("[GET /activitypub/user-id/{user-id}][%d] activitypubPersonOK %+v", 200, o.Payload)
}
func (o *ActivitypubPersonOK) String() string {
return fmt.Sprintf("[GET /activitypub/user-id/{user-id}][%d] activitypubPersonOK %+v", 200, o.Payload)
}
func (o *ActivitypubPersonOK) GetPayload() *models.Person {
return o.Payload
}
func (o *ActivitypubPersonOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.Person)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
// TODO: Thimk about this way to access ap api ...
package activitypub2
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"code.gitea.io/gitea/modules/activitypub2/activitypub"
)
// Default gitea API HTTP client.
var Default = NewHTTPClient(nil)
const (
// DefaultHost is the default Host
// found in Meta (info) section of spec file
DefaultHost string = "localhost"
// DefaultBasePath is the default BasePath
// found in Meta (info) section of spec file
DefaultBasePath string = "/api/v1"
)
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = []string{"http", "https"}
// NewHTTPClient creates a new gitea API HTTP client.
func NewHTTPClient(formats strfmt.Registry) *GiteaAPI {
return NewHTTPClientWithConfig(formats, nil)
}
// NewHTTPClientWithConfig creates a new gitea API HTTP client,
// using a customizable transport config.
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *GiteaAPI {
// ensure nullable parameters have default
if cfg == nil {
cfg = DefaultTransportConfig()
}
// create transport and client
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return New(transport, formats)
}
// New creates a new gitea API client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *GiteaAPI {
// ensure nullable parameters have default
if formats == nil {
formats = strfmt.Default
}
cli := new(GiteaAPI)
cli.Transport = transport
cli.Activitypub = activitypub.New(transport, formats)
return cli
}
// DefaultTransportConfig creates a TransportConfig with the
// default settings taken from the meta section of the spec file.
func DefaultTransportConfig() *TransportConfig {
return &TransportConfig{
Host: DefaultHost,
BasePath: DefaultBasePath,
Schemes: DefaultSchemes,
}
}
// TransportConfig contains the transport related info,
// found in the meta section of the spec file.
type TransportConfig struct {
Host string
BasePath string
Schemes []string
}
// WithHost overrides the default host,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
cfg.Host = host
return cfg
}
// WithBasePath overrides the default basePath,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
cfg.BasePath = basePath
return cfg
}
// WithSchemes overrides the default schemes,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
cfg.Schemes = schemes
return cfg
}
// GiteaAPI is a client for gitea API
type GiteaAPI struct {
Activitypub activitypub.ClientService
Transport runtime.ClientTransport
}
// SetTransport changes the transport on the client and all its subresources
func (c *GiteaAPI) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport
c.Activitypub.SetTransport(transport)
}