GithubHelp home page GithubHelp logo

Comments (20)

abelsilva avatar abelsilva commented on August 26, 2024

Can you check if this would solve your problem?
https://gist.github.com/abelsilva/786daf059ce32246865f5ef9ce19bcfe

putting translations in the UriTemplate of the methods

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

That should work.
Only i have multiple endpoints in multiple Svc files.
I did plan to separate the different endpoints and have each endpoint in a different class.
Is it hard to make the empty uri path for swagger to mean post on parent.
Because that is also how iis handles the uri paths.
Your solution does bring that in line but I had hoped to use a different svc file for every endpoint.

Maybe i can cut u[p the words to mkae it happen :)

like trans to delegate to TRanslations.Svc and then havel "lations" in the method path.
I do wonder if iis works with that.

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

nope does not work.

i do need a slash in between trans and lations now.

get /gw/trans/lations

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

One other issue is that although i have a nullable field and put required=false in the Swagger parameter attribute it still shows the parameter to be required.

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

Would it work if you changed like this?

on Global.asax:

new ServiceRoute("gw", [...]

to

new ServiceRoute("gw/trans",

and on Service:

[SwaggerWcf("/gw")]

to

[SwaggerWcf("/gw/trans")]

and also the methods

UriTemplate = "/translations"

to

UriTemplate = "/lations",

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

I'll check what implication it might have to remove the method name when UriTemplate is empty

It makes sense to not have the method name

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

I'll also check that issue with required

thanks

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

about the required issue, can you show me the function signature?

If I use

        public Book SpecialFunc(string id, Book[] books)

I get books required

If I use

        public Book SpecialFunc(string id, Book[] books = null)

books are not required

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

Hi abelsilva,

Here it goes.

This is in the interface:

[SwaggerWcfPath("By culture and page", "Retrieves a translation by culture and page")]
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/cult/{culture}/page/{page}?reftime={reftime}"
)]
TranslationSet GetCultPage(
[SwaggerWcfParameter(true,"The culture")]string culture,
[SwaggerWcfParameter(true, "The page")]string page,
[SwaggerWcfParameter(false, "The last time we updated the translations")]long reftime);

This is implementation (svc.cs) :

[SwaggerWcf("/gw/translations")]
public class TranslationService:ITranslationService

[SwaggerWcfTag("translations")]
    public TranslationSet GetCultPage(

         [SwaggerWcfParameter(true, "The culture")]string culture,
          [SwaggerWcfParameter(true, "The page")]string page,
          [SwaggerWcfParameter(false, "The last time we updated the translations")]long reftime)
    {
        ............
    }


        i know that long is not nullable so that it would be strange for optional field.
        But it seems to work and when i call without query parameters it just gets 0 as reftime.

this is the base path:

/gw/translations/cult/{culture}/page/{page}

And then in swagger output page I see all 3 fields
with all 3 having required in the value column.

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

oh yeah,
And nullable long is not allowed as query parameter, but i do not have a problem with using a string value.

If i say string and use =null then it will make it an optional parameter?

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

if i change it to:

 [SwaggerWcfTag("translations")]
    public TranslationSet GetCultPage(

         [SwaggerWcfParameter(true, "The culture")]string culture,
          [SwaggerWcfParameter(true, "The page")]string page,
          [SwaggerWcfParameter(false, "The last time we updated the translations")]string reftime=null)

I still see required in the fields of swagger.

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

ok, I was checking this issue with body parameters

now I see the issue you have, it makes sense, it's a bug, I'll check it

thanks

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

If I have


        [SwaggerWcfPath("By culture and page", "Retrieves a translation by culture and page")]
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/cult/{culture}/page/{page}?reftime={reftime}"
            )]
        [SwaggerWcfTag("translations")]
        public Book GetCultPage(
            [SwaggerWcfParameter(true, "The culture")] string culture,
            [SwaggerWcfParameter(true, "The page")] string page,
            [SwaggerWcfParameter(false, "The last time we updated the translations")] long reftime = 0)
        {
            WebOperationContext woc = WebOperationContext.Current;

            if (woc == null)
                return null;

            Book book = Store.Books.FirstOrDefault();
            if (book != null)
            {
                woc.OutgoingResponse.StatusCode = HttpStatusCode.OK;
                return book;
            }

            woc.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
            return null;
        }

I get this in swagger (field not required):
image

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

make sure you are using V 0.1.4

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

if I change the function to

public Book GetCultPage(
            [SwaggerWcfParameter(true, "The culture")] string culture,
            [SwaggerWcfParameter(true, "The page")] string page,
            [SwaggerWcfParameter(false, "The last time we updated the translations")] string reftime = null)

I also see the reftime as not required

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

Hi Abelsilva,

Thank you so much for improving the swagger functionality.

It is great that now it is working with the empty Uri templates.

This makes the interface so much better.

But alas, the fields are still all required in my solution.

I do not understand because I have the exact same parameters
and attibutes of the exact same type

And my swagger still says they are required.

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

are you able to paste the full interface and class?

you may omit the contents of the functions

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

Dear abelsilva,

Thank you so much for your help and quick response and fix.

I got swagger working now the way i hoped it would.

Thank you so much.

from swaggerwcf.

hermanlindner avatar hermanlindner commented on August 26, 2024

The required stuff is working alos :)

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

thanks!

nice to ear it is working

from swaggerwcf.

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.