Macro Help #10558
              
                Unanswered
              
          
                  
                    
                      Vince-Smith
                    
                  
                
                  asked this question in
                Q&A
              
            
            
              Macro Help
            
            #10558
          
          
        Replies: 1 comment 1 reply
-
| 
         You're on the right track — macros in Swagger/OpenAPI (like  
 Example: 'parameterMacro': function (operation, parameter) {
  if (parameter.name === 'year') {
    return 2025
  }
  return parameter.default // fallback to original
} | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I'm struggling to understand the intended use of
macrosand was hoping someone could point me in the right direction.A place these seemed useful to me was to dynamically override years in my defaults/examples.
Unfortunately, I'm finding that neither
modelPropertyMacronorparameterMacroseem very well suited for this despite them being documented as having that purpose...For example you can't introspect the path you're in, so if you want to modify a parameter you can only do so by it's name which effects everything in the entire document. Even though an
operationis passed in toparameterMacro, if there's conditional logic tied to the key that produced that object then it's useless.modelPropertyMacrohas similar problems in that you are given the property but not the name of the property, making it impossible to implement conditional dynamic examples.And finally I can't for the life of me figure out what the default return value is supposed to be...
It seems like I should be doing something like
return parameter.default ?? parameter.valueas my fallback but I can't tell if that's the intent.Am I using these macro's completely wrong??
Beta Was this translation helpful? Give feedback.
All reactions