Giter Site home page Giter Site logo

Comments (12)

AnWeber avatar AnWeber commented on May 18, 2024 1

Support for disconnected environments causes problems in some places:

  • cookieStore is a singleton and needs to be environment related (possibly already a bug, this is a good first issue to contribute)
  • userSessionStore (used for OAuth2 tokens) is also singleton, but notes server url and user name/ clientId and therefore maybe not faulty
  • env and intellij environment files need to be searched, but performance impact should be minimal (test needed). I do not want to cache the files again, because the necessary reset of the cache was not found several times already.
  • My biggest concern currently is the use of .httpyac.json. In this file application settings (log level) and execution settings (request, header, proxy, ...) are mixed up. However, since probably only the execution settings are needed, this should not be a problem. I will just ignore other settings and let vscode internal settings win.

I think the direction is good, but it will take a little while.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024 1

Just a quick update. I already have a working stand locally that searches the folders correctly via tree traversal. There also doesn't seem to be any negative performance impact when parsing or executing.
Since I have a few breaking changes in the configuration (remove dotenv and intellij settings), I don't want to ship it until version 3.0. For this one I would still like to include a hook api.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024 1

Since according to Intellij documentation ECMAScript 5.1 is supported and the Idea is developed with Java, I expect Java Nashorn to be used. And in the youtrack of Idea also Nashorn is mentioned (IDEA-241576). And Nashorn does not support require and anything that goes in that direction is not nice and unfortunately I speak from experience.

and not being able to use libraries like jsonschema would be too limiting

Do you use json schema for simple validation in the test cases? I was wondering myself if this is useful and easy to do, but I don't have much experience with JSON schema. However, my concerns are more about how easily necessary JSON schemas can be generated.

from vscode-httpyac.

gerukin avatar gerukin commented on May 18, 2024 1

IMO a well defined JSONschema can be really useful. It can both help generate the open API style documentation for using the endpoints, and also feed the tests. The spec is so flexible that I find that the JSONschema replaces most (often all) tests I would manually write for the endpoint.

For JSONschema generally I do something like this:

{{
  // centralizes required stuff and makes all tests available here
  module.exports = require('../../tests/')
}}

### Endpoint to test
{{API_URL}}/path/to/stuff

{{
  // I generally test the status with an `is`, `any` or `between` test
  tests.status.is({ test, response, val: 200 })

  // and then test the schema based on a list of schemas in an open API spec
  tests.schema.is({ test, response, name: 'list' })
}}

The schemas are either downloaded or taken from the file system within the open API doc. So there are a bunch of functions for that..

const validate = require('jsonschema').validate

// functions to resolve paths and in-schema references to other files

module.exports.is = async ({ test, response, name }) => {
  // ex: this is where my open API spec lives when present in the repo
  const schema = require(`${baseRespSchemaDir}/${name}.json`)

  test('Schema is valid', function () {
    const validation = validate(
      response.parsedBody,
      convertRefs(schema, baseRespSchemaDir),  // the schema object goes here (custom function because I often deeply divide and nest my schemas)
      { required: true }
    )
    if (validation.valid) return true

    const error = new Error('Response schema is incorrect: ' + validation.errors[0].message)
    error.name = 'SCHEMA_ERR'
    throw error
  })
}

I usually like to keep schema files small and hierarchical like this:

// simple health check endpoint
// schemas/responses/status-ok.json
{
  "type": "object",
  "properties": {
    "status": { "type": "string", "const": "ok" }
  },
  "required": ["status"]
}

// simple list object with dynamic keys
// schemas/objects/list/index.json
{
  "type": "object",
  "patternProperties": {
    "^[A-Z]{3}$": {
      "$ref": "../something/index.json"
    }
  },
  "minProperties": 100
}

// the `something` referenced in the previous schema
// schemas/objects/something/index.json
{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "last_update": {
      "type": "string",
      "pattern": "^20[1-9][0-9]-(([1][0-2])|([0][0-9]))-[0-3][0-9]$"
    }
  },
  "required": ["name"]
}

from vscode-httpyac.

linkdesu avatar linkdesu commented on May 18, 2024

Wow, I have the same requirement! It seems a good chance for me to learn some vscode plugin development. 😂

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

I did not take care to separate the environment settings correctly in my implementation of vscode-httpyac. I have found this error before in workspace projects, but it also applies to this requirement.
I also want to avoid searching for the env files every time I execute a request. VS Code recently supports remote development and the File Magic would possibly delay the execution unnecessarily.
Your initial example could be solved using the httpyac.dotenvDirname setting, but this is not possible for the further example.
I will think again about the environment settings and the .httpyac.json.

@linkdesu I think it's great if you want to actively support me. I'm just afraid that it's not a good example to start with. I have unfortunately the access to the environementStore scattered and also not cleanly separated between program setting and execution settings.

from vscode-httpyac.

gerukin avatar gerukin commented on May 18, 2024

Thank you @AnWeber.

Yes, regarding the first example I had been using the dotenvDirName property, and it's been working fine. But it also means I have to keep .httpyac.json at the root of the project as a result, which is what I am trying to avoid ideally.

I also want to avoid searching for the env files every time I execute a request.

That makes sense. I don't know how much overhead this really represents.

One thing you may be able to do is just scan once when the http file is opened.

  1. file opened -> do you already have a registered root part of this path? if yes you're done, if not..
  2. scan the path to register a new root folder

Maybe 🤔. Anyway, you know what vscode extensions can / should do better than I so I'll let you do the thinking. 😇

from vscode-httpyac.

gerukin avatar gerukin commented on May 18, 2024

Excellent! Sounds like a 3.0 makes the most sense indeed. Monorepo support and hooks are nice major features to have. 👍

Is the disabling of env / IntelliJ env settings temporary or will you no longer support them at all from 3.0 on?


To fully turn POSTman into PASTman in some of my more complicated projects, I plan on testing query dependency (query A and B referencing query X which has to run first and export / set some variables) next week.

Since I want to share code between vscode and IntelliJ users, I will also test the limits of IntelliJ... but it looks like it's just too primitive with no ability to run pre-request code, no dependent queries, and maybe (I need to check) no ability to require. That last one would be a deal breaker for sure for me. If I can't require with IntelliJ I'll just have to ask people to use the CLI only.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

I no longer see the benefit in the settings (only httpyac configuration setting, not support for dotenv or intellij). I would have now dotenv and Intellij configurations enabled by default and based on the presence of such a file, detected the root.

I don't think require is available in Intellij. It is not mentioned in the docs. Dependent queries are only supported, if you manually ececute all queries in the right order.

from vscode-httpyac.

gerukin avatar gerukin commented on May 18, 2024

I no longer see the benefit in the settings (only httpyac configuration setting, not support for dotenv or intellij). I would have now dotenv and Intellij configurations enabled by default and based on the presence of such a file, detected the root.

Makes sense. Even now I actually don't use those settings anyway.

Dependent queries are only supported, if you manually ececute all queries in the right order.

Manually executing in the right order from the editor is essentially what I used to do in rest-client and what people would have to do in IntelliJ. Not ideal but it works indeed.

I don't think require is available in Intellij. It is not mentioned in the docs.

Yes, I was worried when I saw no mention of it and only very simple examples in their docs... but it doesn't necessarily mean it doesn't work. I'll try next week. That honestly would be my biggest problem. IntelliJ's support of > filename.js is a redeeming feature, but it's not flexible enough... and not being able to use libraries like jsonschema would be too limiting. I will probably just set things up so IntelliJ users can at best run the queries to easily see what endpoints return.. but any testing (or writing / testing the tests) will require the httpyac CLI or vscode.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

I will use this week to expand my documentation. The extension has already passed my first test. But I will use the version for one more week at work. You can install them using this guide.

vscode-httpyac-3.0.0-next.0.zip

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

I have now created a separate page for the documentation: https://httpyac.github.io/.
The last few days I have also already used the new version and have not noticed any more serious problems. For the reason I have published this as 3.0.
Through this version, starting from the opened http file, the project root is always searched. Here is described how this is determined.

from vscode-httpyac.

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.