Git Product home page Git Product logo

Comments (6)

SoxZz5 avatar SoxZz5 commented on July 21, 2024 1

Ok i commented customMethods and it work, but when I add back customMethods my doc options are not readed again

Update:

I found that If I instanciate customMethodsHandler before cors or other things, it fail so I assume it's not a real bug mostly me being a noob

from feathers-swagger.

Mairu avatar Mairu commented on July 21, 2024

Hi @SoxZz5,

you did exactly right, by setting it via operations like you did here:

const heroSwaggerOptions = () =>
  createSwaggerServiceOptions({
    schemas: { heroSchema, heroQuerySchema, heroDataSchema, heroPatchSchema },
    docs: {
      description: 'Endpoint to get informations on heroes',
      securities: [],
      operations: {
        get: {
          summary: 'Test'
        },
        find: {
          summary: 'Test'
        }
      }
    },
  });

I have checked that this works for me and it does.

As you only show the code to create the swagger options, my question would then be, how do you use the result of it?

Or does the rest work, like your custom description and the set schemas?

from feathers-swagger.

SoxZz5 avatar SoxZz5 commented on July 21, 2024

I then use it in the service directly like this :

export const hero = (app: Application) => {
  app.use(heroPath, new HeroService(getOptions(app)), {
    methods: heroMethods,
    events: [],
    docs: heroDocs,
  });
  // Initialize hooks
  app.service(heroPath).hooks({
    around: {
      all: [
        schemaHooks.resolveExternal(heroExternalResolver),
        schemaHooks.resolveResult(heroResolver),
      ],
    },
    before: {
      all: [
        schemaHooks.validateQuery(heroQueryValidator),
        schemaHooks.resolveQuery(heroQueryResolver),
      ],
    },
    after: {},
    error: {},
  });
};

And swagger is init like this :

const app: Application = koa(feathers());

// Load our app configuration (see config/ folder)
app.configure(configuration(configurationValidator));

//Set up documentation custom methods handler before Koa middleware
app.configure(swagger.customMethodsHandler);

// Set up Koa middleware
app.use(cors());
app.configure(rateLimiter);

// Removed cause we don't want to have a frontend for feather
//app.use(serveStatic(app.get('public')))
app.use(errorHandler());
app.use(parseAuthentication());
app.use(bodyParser());

// Configure services and transports
app.configure(rest());

//Set up configuration for swagger
app.configure(
  swagger({
    specs: {
      info: {
        title: 'FantasyTop API',
        description: 'FantasyTop API powered by feathers',
        version: '1.0.0',
      },
    },
  })
);

app.configure(feathersCasl());
app.configure(
  socketio({
    cors: {
      origin: app.get('origins'),
    },
  })
);
app.configure(postgresql);
app.configure(services);
app.configure(channels);

// Register hooks that run on all service methods
app.hooks({
  around: {
    all: [logError],
  },
  before: {},
  after: {},
  error: {},
});
// Register application setup and teardown hooks here
app.hooks({
  setup: [],
  teardown: [],
});

export { app };

I give you all the code for better comprehension hope it would help

Btw thanks for your rapid answer

from feathers-swagger.

SoxZz5 avatar SoxZz5 commented on July 21, 2024

The description doesn't work too I did a try by adding this :

    docs: {
      description: 'Endpoint to get informations on heroes TGETATT',
      securities: [],
      operations: {
        find: {
          summary: 'test',
        },
        get: {
          summary: 'test',
        },
      },
tags:
  - name: hero
    description: Endpoint to get informations on heroes

from feathers-swagger.

Mairu avatar Mairu commented on July 21, 2024

From what I see the problem could be that you create a function that returns the result instead of using it, the docs property needs to be an object.

const heroSwaggerOptions = () =>
  createSwaggerServiceOptions({
   ...
 });
 
const heroDocs = heroSwaggerOptions(); // Do you do this, or is this missing?

app.use(heroPath, new HeroService(getOptions(app)), {
  methods: heroMethods,
  events: [],
  docs: heroDocs,
});

I usually do

app.use(heroPath, new HeroService(getOptions(app)), {
  methods: heroMethods,
  events: [],
  docs: createSwaggerServiceOptions({ ... }),
});

but of course, it should be no problem to provide the result of createSwaggerServiceOptions in a different way.

from feathers-swagger.

SoxZz5 avatar SoxZz5 commented on July 21, 2024

Last update to close it, I also got a lot of problem with bun cache, when I call localhost:3030 that's ok, but when I call my generate script I got problem, but no worry it's fixed on my side thanks for your fast answer,

I will have many other question in the futur I pushed my doc on redocly and I'm not really feeling happy with what it generated but it maybe also about how I used feathers, so before asking will try to figure out

from feathers-swagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.